View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.library.fields;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.demo.uif.library.LibraryBase;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.openqa.selenium.By;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public class LibraryFieldsInputAft extends LibraryBase {
28  
29      /**
30       * /kr-krad/kradsampleapp?viewId=Demo-InputFieldView&methodToCall=start
31       */
32      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-InputFieldView&methodToCall=start";
33  
34      @Override
35      public String getBookmarkUrl() {
36          return BOOKMARK_URL;
37      }
38  
39      @Override
40      protected void navigate() throws Exception {
41          navigateToLibraryDemo("Fields", "Input Field");
42      }
43  
44      protected void testInputFieldDefault() throws Exception {
45          WebElement exampleDiv = navigateToExample("Demo-InputField-Example1");
46          WebElement field = findElement(By.cssSelector("div[data-label='InputField 1']"), exampleDiv);
47  
48          String fieldId = field.getAttribute("id");
49          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
50  
51          assertIsVisible("#" + fieldId);
52          assertIsVisible("label[for='" + controlId + "']");
53          WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
54          if (!label.getText().contains("InputField 1:")) {
55              fail("Label text does not match");
56          }
57  
58          assertIsVisible("#" + controlId);
59  
60          waitAndType(By.cssSelector("#" + controlId), "Test InputField");
61  
62          // validate that the value comes after the label
63          findElement(By.cssSelector("label[data-label_for='" + fieldId + "'] + input[id='" + controlId + "']"),
64                  exampleDiv);
65      }
66  
67      protected void testInputFieldAltControl() throws Exception {
68          WebElement exampleDiv = navigateToExample("Demo-InputField-Example2");
69          WebElement field = findElement(By.cssSelector("div[data-label='InputField 2']"), exampleDiv);
70  
71          String fieldId = field.getAttribute("id");
72          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
73  
74          assertIsVisible("#" + fieldId);
75          assertIsVisible("label[for='" + controlId + "']");
76          WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
77          if (!label.getText().contains("InputField 2:")) {
78              fail("Label text does not match");
79          }
80  
81          assertIsVisible("#" + controlId);
82  
83          waitAndType(By.cssSelector("#" + controlId), "Test InputField");
84  
85          // validate that the value comes after the label
86          findElement(By.cssSelector("label[data-label_for='" + fieldId + "'] + textarea[id='" + controlId + "']"),
87                  exampleDiv);
88      }
89  
90      protected void testInputFieldInstructionalText() throws Exception {
91          WebElement exampleDiv = navigateToExample("Demo-InputField-Example3");
92          WebElement field = findElement(By.cssSelector("div[data-label='InputField 3']"), exampleDiv);
93  
94          String fieldId = field.getAttribute("id");
95          String instructionalTextId = fieldId + UifConstants.IdSuffixes.INSTRUCTIONAL;
96          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
97  
98          assertIsVisible("#" + instructionalTextId);
99          assertTextPresent("Instructions for this field", "#" + instructionalTextId, "InputField value not correct");
100 
101         // validate that the instructional text comes after the label
102         findElement(By.cssSelector("label[data-label_for='" + fieldId + "'] + p[id='" + instructionalTextId + "']"),
103                 exampleDiv);
104 
105         // validate that the value comes after the instructional text
106         findElement(By.cssSelector("p[id='" + instructionalTextId + "'] + input[id='" + controlId + "']"),
107                 exampleDiv);
108     }
109 
110     protected void testInputFieldConstraintText() throws Exception {
111         WebElement exampleDiv = navigateToExample("Demo-InputField-Example4");
112         WebElement field = findElement(By.cssSelector("div[data-label='InputField 4']"), exampleDiv);
113 
114         String fieldId = field.getAttribute("id");
115         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
116         String constraintTextId = fieldId + UifConstants.IdSuffixes.CONSTRAINT;
117 
118         assertIsVisible("#" + constraintTextId);
119         assertTextPresent("Text to tell users about constraints this field may have", "#" + constraintTextId,
120                 "InputField value not correct");
121 
122         // validate that the value comes after the label
123         findElement(By.cssSelector("label[data-label_for='" + fieldId + "'] + input[id='" + controlId + "']"),
124                 exampleDiv);
125 
126         // validate that the constraint text comes after the value
127         findElement(By.cssSelector("input[id='" + controlId + "'] ~ p[id='" + constraintTextId + "']"), exampleDiv);
128     }
129 
130     protected void testInputFieldLabelTop() throws Exception {
131         WebElement exampleDiv = navigateToExample("Demo-InputField-Example5");
132         WebElement field = findElement(By.cssSelector("div[data-label='Label Top Field']"), exampleDiv);
133 
134         String fieldId = field.getAttribute("id");
135         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
136 
137         assertIsVisible("#" + fieldId);
138         assertIsVisible("label[for='" + controlId + "']");
139         WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
140         if (!label.getText().contains("Label Top Field")) {
141             fail("Label text does not match");
142         }
143 
144         WebElement labelSpan = findElement(By.cssSelector("label[data-label_for='" + fieldId + "']"), field);
145         // top and bottom add the uif-labelBlock class
146         if (!labelSpan.getAttribute("class").contains("uif-labelBlock")) {
147             fail("Label span does not contain the appropriate class expected");
148         }
149     }
150 
151     protected void testInputFieldLabelRight() throws Exception {
152         WebElement exampleDiv = navigateToExample("Demo-InputField-Example6");
153         WebElement field = findElement(By.cssSelector("div[data-label='Label Right Field']"), exampleDiv);
154 
155         String fieldId = field.getAttribute("id");
156         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
157 
158         assertIsVisible("#" + controlId);
159 
160         assertIsVisible("#" + fieldId);
161         assertIsVisible("label[for='" + controlId + "']");
162         WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
163         if (!label.getText().contains("Label Right Field")) {
164             fail("Label text does not match");
165         }
166 
167         // validate that the label comes after the value
168         findElement(By.cssSelector("input[id='" + controlId + "'] + label[data-label_for='" + fieldId + "']"),
169                 exampleDiv);
170     }
171 
172     protected void testInputFieldQuickfinder() throws Exception {
173         WebElement exampleDiv = navigateToExample("Demo-InputField-Example7");
174         WebElement field = findElement(By.cssSelector("div[data-label='Quickfinder Field']"), exampleDiv);
175 
176         String fieldId = field.getAttribute("id");
177         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
178         String quickfinderId = findElement(By.xpath("//div[@data-label=\"Quickfinder Field\"]/div/div/button")).getAttribute("id");
179 
180         // validate that the quickfinder comes after the value
181         findElement(By.cssSelector("input[id='" + controlId + "'] + div>button[id='" + quickfinderId + "']"), exampleDiv);
182 
183         assertIsVisible("#" + quickfinderId);
184 
185         waitAndClickById(quickfinderId);
186 
187         Thread.sleep(2000);
188 
189         gotoLightBox();
190 
191         WebElement travelAccountNumberField = driver.findElement(By.cssSelector(
192                 "div[data-label='Travel Account Number']"));
193 
194         String travelAccountNumberFieldId = travelAccountNumberField.getAttribute("id");
195         String travelAccountNumberControlId = travelAccountNumberFieldId + UifConstants.IdSuffixes.CONTROL;
196 
197         findElement(By.cssSelector("#" + travelAccountNumberControlId), travelAccountNumberField).sendKeys("a1");
198         waitAndClickSearch3();
199         waitAndClickReturnValue();
200 //        waitAndClickByLinkText("Quickfinder"); // work around for Quickfinder not loaded on return
201         waitForElementPresentByXpath("//input[@name='inputField7' and @value='a1']");
202     }
203 
204     protected void testInputFieldInquiry() throws Exception {
205         WebElement exampleDiv = navigateToExample("Demo-InputField-Example9");
206         WebElement field = findElement(By.cssSelector("div[data-label='Inquiry Field']"), exampleDiv);
207 
208         String fieldId = field.getAttribute("id");
209         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
210         String inquiryId = field.findElement(By.cssSelector(".uif-action")).getAttribute("id");
211 
212         // validate that the inquiry comes after the value
213         findElement(By.cssSelector("input[id='" + controlId + "'] + div > button[id='" + inquiryId + "']"), exampleDiv);
214 
215         assertIsVisible("#" + inquiryId);
216 
217         waitAndClickById(inquiryId);
218 
219         Thread.sleep(2000);
220 
221         gotoLightBox();
222         assertTextPresent("Travel Account");
223         gotoLightBoxIframe();
224 
225         waitAndClickButtonByText("Close");
226         selectTopFrame();
227     }
228 
229     protected void testInputFieldRequired() throws Exception {
230         WebElement exampleDiv = navigateToExample("Demo-InputField-Example11");
231         WebElement field = findElement(By.cssSelector("div[data-label='Required Field']"), exampleDiv);
232 
233         String fieldId = field.getAttribute("id");
234         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
235         String errorId = fieldId + UifConstants.IdSuffixes.ERRORS;
236 
237         WebElement requiredAsterisk = findElement(By.cssSelector("span.uif-requiredMessage"), field);
238         if (!requiredAsterisk.getText().contains("*")) {
239             fail("Label asterisk for required field does not appear");
240         }
241 
242         assertIsVisible("#" + controlId);
243 
244         waitAndClick(By.cssSelector("#" + controlId));
245         Thread.sleep(3000);
246         waitAndClick(By.cssSelector("#" + fieldId));
247         typeTab();
248 //        fireMouseOverEventByName("inputField11");
249         if (!field.getAttribute("class").contains("uif-hasError")) {
250             fail("Control does not show error class");
251         }
252         assertElementPresent("#" + errorId + " img[src$='/krad/images/validation/error.png']");
253     }
254 
255     protected void testInputFieldUppercase() throws Exception {
256         WebElement exampleDiv = navigateToExample("Demo-InputField-Example12");
257         WebElement field = findElement(By.cssSelector("div[data-label='Uppercase field']"), exampleDiv);
258 
259         String fieldId = field.getAttribute("id");
260         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
261 
262         assertIsVisible("#" + controlId);
263 
264         waitAndType(By.cssSelector("#" + controlId), "Test InputField");
265 
266         assertTextNotPresent("TEST INPUTFIELD", "Control text did not appear as uppercase");
267     }
268 
269     protected void testInputFieldWidgetInputOnlyWithQuickFinder() throws Exception {
270         //There is nothing under this section on which tests can be applied.
271     	waitAndClickByLinkText("widgetInputOnly with Quickfinder");
272     }
273     
274     protected void testInputFieldWidgetInputOnlyWithInquiry() throws Exception {
275     	waitAndClickByLinkText("widgetInputOnly with Inquiry");
276     	waitAndClickByXpath("//div[@data-parent='Demo-InputField-Example10']/span/input[@type='image' and @title='Direct Inquiry']");
277         gotoLightBoxIframe();
278     	waitForTextPresent("a2");
279     	waitForTextPresent("Travel Account 2");
280     	waitForTextPresent("EAT - Expense");
281     	waitForTextPresent("fran");
282     	waitAndClickButtonByText("Close");
283     	selectTopFrame();
284     }
285     
286     protected void testInputFieldDisableNativeAutocomplete() throws Exception {
287     	waitAndClickByLinkText("Disable Native Autocomplete");
288     	waitForElementPresentByXpath("//input[@name='inputField13' and @autocomplete='off']");
289     }
290     
291     protected void testInputFieldInputAddons() throws Exception {
292     	waitAndClickByLinkText("Input Addons");
293     	waitForTextPresent(".00 ");
294     	waitForElementPresentByXpath("//div[@data-parent='Demo-InputField-Example14']/div/span/a");
295     	waitForElementPresentByXpath("//div[@data-parent='Demo-InputField-Example14']/div/span/a[@class='uif-actionLink icon-facebook3']");
296     	waitForElementPresentByXpath("//div[@data-parent='Demo-InputField-Example14']/div/span/a[@class='uif-actionLink icon-twitter3']");
297     	waitForElementPresentByXpath("//div[@data-parent='Demo-InputField-Example14']/div/span/a[@class='uif-actionLink icon-youtube']");
298     }
299     
300     protected void testInputFieldExamples() throws Exception {
301         testInputFieldDefault();
302         testInputFieldAltControl();
303         testInputFieldInstructionalText();
304         testInputFieldConstraintText();
305 //        testInputFieldLabelTop(); // removed from example
306 //        testInputFieldLabelRight(); // removed from example
307         testInputFieldWidgetInputOnlyWithQuickFinder();
308         testInputFieldUppercase();
309         testInputFieldDisableNativeAutocomplete();
310         testInputFieldInputAddons();
311         testInputFieldRequired();
312         testInputFieldInquiry();
313         testInputFieldQuickfinder();
314     }
315 
316     @Test
317     public void testInputFieldExamplesBookmark() throws Exception {
318         testInputFieldExamples();
319         passed();
320     }
321 
322     @Test
323     public void testInputFieldExamplesNav() throws Exception {
324         testInputFieldExamples();
325         passed();
326     }
327 }