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