001    package edu.samplu.krad.demo.uif.library;
002    
003    import org.junit.Test;
004    import org.kuali.rice.krad.uif.UifConstants;
005    import org.openqa.selenium.By;
006    import org.openqa.selenium.WebElement;
007    
008    /**
009     * @author Kuali Rice Team (rice.collab@kuali.org)
010     */
011    public class DemoLibraryFieldsInputSmokeTest extends DemoLibraryBase {
012    
013        /**
014         * /kr-krad/kradsampleapp?viewId=Demo-InputField-View&methodToCall=start
015         */
016        public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-InputField-View&methodToCall=start";
017    
018        @Override
019        public String getBookmarkUrl() {
020            return BOOKMARK_URL;
021        }
022    
023        @Override
024        protected void navigate() throws Exception {
025            navigateToLibraryDemo("Fields", "Input Field");
026        }
027    
028        protected void testInputFieldDefault() throws Exception {
029            WebElement exampleDiv = navigateToExample("Demo-InputField-Example1");
030            WebElement field = findElement(By.cssSelector("div[data-label='InputField 1']"), exampleDiv);
031    
032            String fieldId = field.getAttribute("id");
033            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
034    
035            assertIsVisible("#" + fieldId);
036            assertIsVisible("label[for='" + controlId + "']");
037            WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
038            if (!label.getText().contains("InputField 1:")) {
039                fail("Label text does not match");
040            }
041    
042            assertIsVisible("#" + controlId);
043    
044            waitAndType(By.cssSelector("#" + controlId), "Test InputField");
045    
046            // validate that the value comes after the label
047            findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + input[id='" + controlId + "']"),
048                    exampleDiv);
049        }
050    
051        protected void testInputFieldAltControl() throws Exception {
052            WebElement exampleDiv = navigateToExample("Demo-InputField-Example2");
053            WebElement field = findElement(By.cssSelector("div[data-label='InputField 2']"), exampleDiv);
054    
055            String fieldId = field.getAttribute("id");
056            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
057    
058            assertIsVisible("#" + fieldId);
059            assertIsVisible("label[for='" + controlId + "']");
060            WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
061            if (!label.getText().contains("InputField 2:")) {
062                fail("Label text does not match");
063            }
064    
065            assertIsVisible("#" + controlId);
066    
067            waitAndType(By.cssSelector("#" + controlId), "Test InputField");
068    
069            // validate that the value comes after the label
070            findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + textarea[id='" + controlId + "']"),
071                    exampleDiv);
072        }
073    
074        protected void testInputFieldInstructionalText() throws Exception {
075            WebElement exampleDiv = navigateToExample("Demo-InputField-Example3");
076            WebElement field = findElement(By.cssSelector("div[data-label='InputField 3']"), exampleDiv);
077    
078            String fieldId = field.getAttribute("id");
079            String instructionalTextId = fieldId + UifConstants.IdSuffixes.INSTRUCTIONAL + UifConstants.IdSuffixes.SPAN;
080            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
081    
082            assertIsVisible("#" + instructionalTextId);
083            assertTextPresent("Instructions for this field", "#" + instructionalTextId, "InputField value not correct");
084    
085            // validate that the instructional text comes after the label
086            findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + span[id='" + instructionalTextId + "']"),
087                    exampleDiv);
088    
089            // validate that the value comes after the instructional text
090            findElement(By.cssSelector("span[id='" + instructionalTextId + "'] + input[id='" + controlId + "']"),
091                    exampleDiv);
092        }
093    
094        protected void testInputFieldConstraintText() throws Exception {
095            WebElement exampleDiv = navigateToExample("Demo-InputField-Example4");
096            WebElement field = findElement(By.cssSelector("div[data-label='InputField 4']"), exampleDiv);
097    
098            String fieldId = field.getAttribute("id");
099            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
100            String constraintTextId = fieldId + UifConstants.IdSuffixes.CONSTRAINT + UifConstants.IdSuffixes.SPAN;
101    
102            assertIsVisible("#" + constraintTextId);
103            assertTextPresent("Text to tell users about constraints this field may have", "#" + constraintTextId,
104                    "InputField value not correct");
105    
106            // validate that the value comes after the label
107            findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + input[id='" + controlId + "']"),
108                    exampleDiv);
109    
110            // validate that the constraint text comes after the value
111            findElement(By.cssSelector("input[id='" + controlId + "'] ~ span[id='" + constraintTextId + "']"), exampleDiv);
112        }
113    
114        protected void testInputFieldLabelTop() throws Exception {
115            WebElement exampleDiv = navigateToExample("Demo-InputField-Example5");
116            WebElement field = findElement(By.cssSelector("div[data-label='Label Top Field']"), exampleDiv);
117    
118            String fieldId = field.getAttribute("id");
119            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
120    
121            assertIsVisible("#" + fieldId);
122            assertIsVisible("label[for='" + controlId + "']");
123            WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
124            if (!label.getText().contains("Label Top Field")) {
125                fail("Label text does not match");
126            }
127    
128            WebElement labelSpan = findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"), field);
129            // top and bottom add the uif-labelBlock class
130            if (!labelSpan.getAttribute("class").contains("uif-labelBlock")) {
131                fail("Label span does not contain the appropriate class expected");
132            }
133        }
134    
135        protected void testInputFieldLabelRight() throws Exception {
136            WebElement exampleDiv = navigateToExample("Demo-InputField-Example6");
137            WebElement field = findElement(By.cssSelector("div[data-label='Label Right Field']"), exampleDiv);
138    
139            String fieldId = field.getAttribute("id");
140            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
141    
142            assertIsVisible("#" + controlId);
143    
144            assertIsVisible("#" + fieldId);
145            assertIsVisible("label[for='" + controlId + "']");
146            WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
147            if (!label.getText().contains("Label Right Field")) {
148                fail("Label text does not match");
149            }
150    
151            // validate that the label comes after the value
152            findElement(By.cssSelector("input[id='" + controlId + "'] + span[data-label_for='" + fieldId + "']"),
153                    exampleDiv);
154        }
155    
156        protected void testInputFieldQuickfinder() throws Exception {
157            WebElement exampleDiv = navigateToExample("Demo-InputField-Example7");
158            WebElement field = findElement(By.cssSelector("div[data-label='Quickfinder Field']"), exampleDiv);
159    
160            String fieldId = field.getAttribute("id");
161            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
162            String quickfinderId = findElement(By.cssSelector(".uif-actionImage"), field).getAttribute("id");
163    
164            // validate that the quickfinder comes after the value
165            findElement(By.cssSelector("input[id='" + controlId + "'] + input[id='" + quickfinderId + "']"), exampleDiv);
166    
167            assertIsVisible("#" + quickfinderId);
168    
169            waitAndClickById(quickfinderId);
170    
171            Thread.sleep(2000);
172    
173            driver.switchTo().frame(driver.findElement(By.cssSelector(".fancybox-iframe")));
174    
175            WebElement travelAccountNumberField = driver.findElement(By.cssSelector(
176                    "div[data-label='Travel Account Number']"));
177    
178            String travelAccountNumberFieldId = travelAccountNumberField.getAttribute("id");
179            String travelAccountNumberControlId = travelAccountNumberFieldId + UifConstants.IdSuffixes.CONTROL;
180    
181            findElement(By.cssSelector("#" + travelAccountNumberControlId), travelAccountNumberField).sendKeys("a1");
182            waitAndClickSearch3();
183            waitAndClickReturnValue();
184    
185            selectTopFrame();
186    
187            assertIsVisible("#" + controlId);
188            assertTextPresent("a1", "Control text did not appear");
189        }
190    
191        protected void testInputFieldInquiry() throws Exception {
192            WebElement exampleDiv = navigateToExample("Demo-InputField-Example9");
193            WebElement field = findElement(By.cssSelector("div[data-label='Inquiry Field']"), exampleDiv);
194    
195            String fieldId = field.getAttribute("id");
196            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
197            String inquiryId = field.findElement(By.cssSelector(".uif-actionImage")).getAttribute("id");
198    
199            // validate that the inquiry comes after the value
200            findElement(By.cssSelector("input[id='" + controlId + "'] + input[id='" + inquiryId + "']"), exampleDiv);
201    
202            assertIsVisible("#" + inquiryId);
203    
204            waitAndClickById(inquiryId);
205    
206            Thread.sleep(2000);
207    
208            driver.switchTo().frame(driver.findElement(By.cssSelector(".fancybox-iframe")));
209            checkForIncidentReport("Travel Account Inquiry");
210            assertTextPresent("Travel Account");
211            selectTopFrame();
212            gotoIframeByXpath("//iframe[@class='fancybox-iframe']");
213    
214            waitAndClickButtonByText("Close");
215        }
216    
217        protected void testInputFieldRequired() throws Exception {
218            WebElement exampleDiv = navigateToExample("Demo-InputField-Example11");
219            WebElement field = findElement(By.cssSelector("div[data-label='Required Field']"), exampleDiv);
220    
221            String fieldId = field.getAttribute("id");
222            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
223            String errorId = fieldId + UifConstants.IdSuffixes.ERRORS;
224    
225            WebElement requiredAsterisk = findElement(By.cssSelector("span.uif-requiredMessage"), field);
226            if (!requiredAsterisk.getText().contains("*")) {
227                fail("Label asterisk for required field does not appear");
228            }
229    
230            assertIsVisible("#" + controlId);
231    
232            waitAndClick(By.cssSelector("#" + controlId));
233            waitAndClick(By.cssSelector("#" + fieldId));
234            fireMouseOverEventByName("inputField10");
235            if (!field.getAttribute("class").contains("uif-hasError")) {
236                fail("Control does not show error class");
237            }
238            assertElementPresent("#" + errorId + " img[src$='/krad/images/validation/error.png']");
239        }
240    
241        protected void testInputFieldUppercase() throws Exception {
242            WebElement exampleDiv = navigateToExample("Demo-InputField-Example12");
243            WebElement field = findElement(By.cssSelector("div[data-label='Uppercase field']"), exampleDiv);
244    
245            String fieldId = field.getAttribute("id");
246            String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
247    
248            assertIsVisible("#" + controlId);
249    
250            waitAndType(By.cssSelector("#" + controlId), "Test InputField");
251    
252            assertTextNotPresent("TEST INPUTFIELD", "Control text did not appear as uppercase");
253        }
254    
255        protected void testInputFieldExamples() throws Exception {
256            testInputFieldDefault();
257            testInputFieldAltControl();
258            testInputFieldInstructionalText();
259            testInputFieldConstraintText();
260            testInputFieldLabelTop();
261            testInputFieldLabelRight();
262            testInputFieldQuickfinder();
263            testInputFieldInquiry();
264            testInputFieldRequired();
265            testInputFieldUppercase();
266        }
267    
268        @Test
269        public void testInputFieldExamplesBookmark() throws Exception {
270            testInputFieldExamples();
271            passed();
272        }
273    
274        @Test
275        public void testInputFieldExamplesNav() throws Exception {
276            testInputFieldExamples();
277            passed();
278        }
279    
280        @Test
281        public void testInputFieldDefaultBookmark() throws Exception {
282            testInputFieldDefault();
283            passed();
284        }
285    
286        @Test
287        public void testInputFieldDefaultNav() throws Exception {
288            testInputFieldDefault();
289            passed();
290        }
291    
292        @Test
293        public void testInputFieldAltControlBookmark() throws Exception {
294            testInputFieldAltControl();
295            passed();
296        }
297    
298        @Test
299        public void testInputFieldAltControlNav() throws Exception {
300            testInputFieldAltControl();
301            passed();
302        }
303    
304        @Test
305        public void testInputFieldInstructionalTextBookmark() throws Exception {
306            testInputFieldInstructionalText();
307            passed();
308        }
309    
310        @Test
311        public void testInputFieldInstructionalTextNav() throws Exception {
312            testInputFieldInstructionalText();
313            passed();
314        }
315    
316        @Test
317        public void testInputFieldConstraintTextBookmark() throws Exception {
318            testInputFieldConstraintText();
319            passed();
320        }
321    
322        @Test
323        public void testInputFieldConstraintTextNav() throws Exception {
324            testInputFieldConstraintText();
325            passed();
326        }
327    
328        @Test
329        public void testInputFieldLabelTopBookmark() throws Exception {
330            testInputFieldLabelTop();
331            passed();
332        }
333    
334        @Test
335        public void testInputFieldLabelTopNav() throws Exception {
336            testInputFieldLabelTop();
337            passed();
338        }
339    
340        @Test
341        public void testInputFieldLabelRightBookmark() throws Exception {
342            testInputFieldLabelRight();
343            passed();
344        }
345    
346        @Test
347        public void testInputFieldLabelRightNav() throws Exception {
348            testInputFieldLabelRight();
349            passed();
350        }
351    
352        @Test
353        public void testInputFieldQuickfinderBookmark() throws Exception {
354            testInputFieldQuickfinder();
355            passed();
356        }
357    
358        @Test
359        public void testInputFieldQuickfinderNav() throws Exception {
360            testInputFieldQuickfinder();
361            passed();
362        }
363    
364        @Test
365        public void testInputFieldInquiryBookmark() throws Exception {
366            testInputFieldInquiry();
367            passed();
368        }
369    
370        @Test
371        public void testInputFieldInquiryNav() throws Exception {
372            testInputFieldInquiry();
373            passed();
374        }
375    
376        @Test
377        public void testInputFieldRequiredBookmark() throws Exception {
378            testInputFieldRequired();
379            passed();
380        }
381    
382        @Test
383        public void testInputFieldRequiredNav() throws Exception {
384            testInputFieldRequired();
385            passed();
386        }
387    
388        @Test
389        public void testInputFieldUppercaseBookmark() throws Exception {
390            testInputFieldUppercase();
391            passed();
392        }
393    
394        @Test
395        public void testInputFieldUppercaseNav() throws Exception {
396            testInputFieldUppercase();
397            passed();
398        }
399    }