1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.krad.validationmessagesview;
17
18 import com.thoughtworks.selenium.SeleneseTestBase;
19 import org.kuali.rice.testtools.selenium.Failable;
20 import org.kuali.rice.testtools.selenium.ITUtil;
21 import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
22 import org.openqa.selenium.By;
23
24
25
26
27
28
29 public abstract class ClientErrorsAbstractSmokeTestBase extends WebDriverLegacyITBase {
30
31
32
33
34 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start";
35
36 protected void bookmark() {
37 open(ITUtil.getBaseUrlString() + BOOKMARK_URL);
38 }
39
40
41
42
43
44
45
46 @Override
47 public String getTestUrl() {
48 return ITUtil.PORTAL;
49 }
50
51 protected void navigation() throws InterruptedException {
52 waitAndClickKRAD();
53 waitAndClickByXpath(VALIDATION_FRAMEWORK_DEMO_XPATH);
54 switchToWindow(KUALI_VIEW_WINDOW_TITLE);
55 }
56
57 protected void testClientErrorsNav(Failable failable) throws Exception {
58 navigation();
59 testClientErrors();
60 passed();
61 }
62
63 protected void testClientErrorsBookmark(Failable failable) throws Exception {
64 testClientErrors();
65 passed();
66 }
67
68 protected void testClientErrors() throws Exception {
69 fireEvent("field1", "focus");
70 fireEvent("field1", "blur");
71 Thread.sleep(3000);
72 fireMouseOverEventByName("field1");
73 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field1", "aria-invalid"));
74 assertAttributeClassRegexMatches("field1", REGEX_ERROR);
75 SeleneseTestBase.assertTrue(isTextPresent("Required"));
76
77 fireMouseOverEventByName("field1");
78
79 for (int second = 0;; second++) {
80 if (second >= 10) {
81 SeleneseTestBase.fail(TIMEOUT_MESSAGE);
82 }
83
84 try {
85 if (isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
86 break;
87 }
88 } catch (Exception e) {}
89
90 Thread.sleep(1000);
91 }
92
93 SeleneseTestBase.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field"));
94
95 waitAndTypeByName("field1", "a");
96 fireEvent("field1", "blur");
97 fireMouseOverEventByName("field1");
98
99 for (int second = 0;; second++) {
100 if (second >= 10) {
101 SeleneseTestBase.fail(TIMEOUT_MESSAGE);
102 }
103
104 try {
105 if (!isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
106 break;
107 }
108 } catch (Exception e) {}
109
110 Thread.sleep(1000);
111 }
112
113 SeleneseTestBase.assertFalse(isVisibleByXpath(
114 "//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']"));
115
116 fireEvent("field1", "blur");
117 Thread.sleep(500);
118 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field1' and @aria-invalid]"));
119 assertAttributeClassRegexMatches("field1", REGEX_VALID);
120 SeleneseTestBase.assertTrue(isTextPresent("Required"));
121
122 fireEvent("field2", "focus");
123 fireEvent("field2", "blur");
124 fireMouseOverEventByName("field2");
125 Thread.sleep(500);
126
127 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-required"));
128 assertAttributeClassRegexMatches("field2", REGEX_ERROR);
129 SeleneseTestBase.assertTrue(isTextPresent("Required"));
130
131 fireEvent("field2", "focus");
132 waitAndTypeByName("field2", "a");
133 fireEvent("field2", "blur");
134 Thread.sleep(500);
135 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
136 assertAttributeClassRegexMatches("field2", REGEX_VALID);
137 SeleneseTestBase.assertFalse(isElementPresentByXpath("//textarea[@name='field2']/../img[@alt='Error']"));
138
139 fireEvent("field3", "focus");
140 fireEvent("field3", "blur");
141 fireMouseOverEventByName("field3");
142 Thread.sleep(500);
143 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field3", "aria-invalid"));
144 assertAttributeClassRegexMatches("field3", REGEX_ERROR);
145 SeleneseTestBase.assertTrue(isTextPresent("Required"));
146
147 fireEvent("field3", "focus");
148 selectByName("field3", "Option 1");
149 fireEvent("field3", "blur");
150 Thread.sleep(500);
151 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]"));
152 assertAttributeClassRegexMatches("field3", REGEX_VALID);
153 SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']"));
154
155 fireEvent("field114", "focus");
156 fireMouseOverEventByName("field114");
157 driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click();
158 fireEvent("field114", "blur");
159 Thread.sleep(500);
160 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field114", "aria-invalid"));
161 assertAttributeClassRegexMatches("field114", REGEX_ERROR);
162 SeleneseTestBase.assertTrue(isTextPresent("Required"));
163
164 fireEvent("field114", "focus");
165 selectByName("field114", "Option 1");
166 fireEvent("field114", "blur");
167 Thread.sleep(500);
168 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field114' and @aria-invalid]"));
169 assertAttributeClassRegexMatches("field114", REGEX_VALID);
170 SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field114']/../img[@alt='Error']"));
171
172 fireEvent("field117", "3", "focus");
173 uncheckByXpath("//*[@name='field117' and @value='3']");
174 fireEvent("field117", "blur");
175 fireMouseOverEventByName("field117");
176
177 for (int second = 0;; second++) {
178 if (second >= 10) {
179 SeleneseTestBase.fail(TIMEOUT_MESSAGE);
180 }
181
182 try {
183 if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
184 break;
185 }
186 } catch (Exception e) {}
187
188 Thread.sleep(1000);
189 }
190
191 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByXpath("//*[@name='field117' and @value='1']",
192 "aria-invalid"));
193 SeleneseTestBase.assertTrue(waitAndGetAttributeByXpath("//*[@name='field117' and @value='1']", "class").matches(
194 REGEX_ERROR));
195 SeleneseTestBase.assertTrue(isTextPresent("Required"));
196
197 fireEvent("field117", "3", "focus");
198 checkByXpath("//*[@name='field117' and @value='3']");
199 fireEvent("field117", "3", "blur");
200
201 for (int second = 0;; second++) {
202 if (second >= waitSeconds) {
203 SeleneseTestBase.fail(TIMEOUT_MESSAGE);
204 }
205
206 try {
207 if (!isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) {
208 break;
209 }
210 } catch (Exception e) {}
211
212 Thread.sleep(1000);
213 }
214
215 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field117' and @value='3' and @aria-invalid]"));
216 SeleneseTestBase.assertTrue(waitAndGetAttributeByXpath("//*[@name='field117' and @value='3']", "class").matches(REGEX_VALID));
217 SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']"));
218
219 fireEvent("bField1", "focus");
220 uncheckByName("bField1");
221 fireEvent("bField1", "blur");
222 fireMouseOverEventByName("bField1");
223 Thread.sleep(500);
224 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("bField1", "aria-invalid"));
225 assertAttributeClassRegexMatches("bField1", REGEX_ERROR);
226 SeleneseTestBase.assertTrue(isTextPresent("Required"));
227
228 fireEvent("bField1", "focus");
229 checkByName("bField1");
230 fireEvent("bField1", "blur");
231 Thread.sleep(500);
232 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='bField1' and @aria-invalid]"));
233 assertAttributeClassRegexMatches("bField1", REGEX_VALID);
234 SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
235
236 fireEvent("field115", "3", "focus");
237 uncheckByXpath("//*[@name='field115' and @value='3']");
238 uncheckByXpath("//*[@name='field115' and @value='4']");
239 fireEvent("field115", "blur");
240 fireMouseOverEventByName("field115");
241
242 for (int second = 0;; second++) {
243 if (second >= waitSeconds) {
244 SeleneseTestBase.fail(TIMEOUT_MESSAGE);
245 }
246
247 try {
248 if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
249 break;
250 }
251 } catch (Exception e) {}
252
253 Thread.sleep(1000);
254 }
255
256 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByXpath("//*[@name='field115' and @value='1']",
257 "aria-invalid"));
258 SeleneseTestBase.assertTrue(waitAndGetAttributeByXpath("//*[@name='field115' and @value='1']", "class").matches(REGEX_ERROR));
259 SeleneseTestBase.assertTrue(isTextPresent("Required"));
260
261 fireEvent("field115", "3", "focus");
262 checkByXpath("//*[@name='field115' and @value='3']");
263 checkByXpath("//*[@name='field115' and @value='4']");
264 fireEvent("field115", "blur");
265
266 for (int second = 0;; second++) {
267 if (second >= waitSeconds) {
268 SeleneseTestBase.fail(TIMEOUT_MESSAGE);
269 }
270
271 try {
272 if (!isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) {
273 break;
274 }
275 } catch (Exception e) {}
276
277 Thread.sleep(1000);
278 }
279
280 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field115' and @value='3' and @aria-invalid]"));
281 SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']"));
282 }
283 }