1 package edu.samplu.krad.demo.uif.library;
2
3 import org.junit.Test;
4 import org.kuali.rice.krad.uif.UifConstants;
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.WebElement;
7
8
9
10
11 public class DemoLibraryFieldsInputSmokeTest extends DemoLibraryBase {
12
13
14
15
16 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-InputField-View&methodToCall=start";
17
18 @Override
19 public String getBookmarkUrl() {
20 return BOOKMARK_URL;
21 }
22
23 @Override
24 protected void navigate() throws Exception {
25 navigateToLibraryDemo("Fields", "Input Field");
26 }
27
28 protected void testInputFieldDefault() throws Exception {
29 WebElement exampleDiv = navigateToExample("Demo-InputField-Example1");
30 WebElement field = findElement(By.cssSelector("div[data-label='InputField 1']"), exampleDiv);
31
32 String fieldId = field.getAttribute("id");
33 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
34
35 assertIsVisible("#" + fieldId);
36 assertIsVisible("label[for='" + controlId + "']");
37 WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
38 if (!label.getText().contains("InputField 1:")) {
39 fail("Label text does not match");
40 }
41
42 assertIsVisible("#" + controlId);
43
44 waitAndType(By.cssSelector("#" + controlId), "Test InputField");
45
46
47 findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + input[id='" + controlId + "']"),
48 exampleDiv);
49 }
50
51 protected void testInputFieldAltControl() throws Exception {
52 WebElement exampleDiv = navigateToExample("Demo-InputField-Example2");
53 WebElement field = findElement(By.cssSelector("div[data-label='InputField 2']"), exampleDiv);
54
55 String fieldId = field.getAttribute("id");
56 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
57
58 assertIsVisible("#" + fieldId);
59 assertIsVisible("label[for='" + controlId + "']");
60 WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
61 if (!label.getText().contains("InputField 2:")) {
62 fail("Label text does not match");
63 }
64
65 assertIsVisible("#" + controlId);
66
67 waitAndType(By.cssSelector("#" + controlId), "Test InputField");
68
69
70 findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + textarea[id='" + controlId + "']"),
71 exampleDiv);
72 }
73
74 protected void testInputFieldInstructionalText() throws Exception {
75 WebElement exampleDiv = navigateToExample("Demo-InputField-Example3");
76 WebElement field = findElement(By.cssSelector("div[data-label='InputField 3']"), exampleDiv);
77
78 String fieldId = field.getAttribute("id");
79 String instructionalTextId = fieldId + UifConstants.IdSuffixes.INSTRUCTIONAL + UifConstants.IdSuffixes.SPAN;
80 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
81
82 assertIsVisible("#" + instructionalTextId);
83 assertTextPresent("Instructions for this field", "#" + instructionalTextId, "InputField value not correct");
84
85
86 findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + span[id='" + instructionalTextId + "']"),
87 exampleDiv);
88
89
90 findElement(By.cssSelector("span[id='" + instructionalTextId + "'] + input[id='" + controlId + "']"),
91 exampleDiv);
92 }
93
94 protected void testInputFieldConstraintText() throws Exception {
95 WebElement exampleDiv = navigateToExample("Demo-InputField-Example4");
96 WebElement field = findElement(By.cssSelector("div[data-label='InputField 4']"), exampleDiv);
97
98 String fieldId = field.getAttribute("id");
99 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
107 findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + input[id='" + controlId + "']"),
108 exampleDiv);
109
110
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
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
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
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
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 }