1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.samplu.krad.validationmessagesview;
18
19 import com.thoughtworks.selenium.Selenium;
20 import junit.framework.Assert;
21 import org.openqa.selenium.firefox.FirefoxDriver;
22 import org.openqa.selenium.WebDriver;
23 import org.openqa.selenium.WebDriverBackedSelenium;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 public class ClientErrorsIT {
29 private Selenium selenium;
30
31 @Before
32 public void setUp() throws Exception {
33 WebDriver driver = new FirefoxDriver();
34 selenium = new WebDriverBackedSelenium(driver,
35 "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start");
36
37
38 selenium.open(
39 "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start");
40 Assert.assertEquals("Login", selenium.getTitle());
41 selenium.type("__login_user", "admin");
42 selenium.click("//input[@value='Login']");
43 selenium.waitForPageToLoad("30000");
44 }
45
46 @Test
47 public void testClientErrors() throws Exception {
48 selenium.fireEvent("name=field1", "focus");
49 selenium.type("name=field1", "");
50 selenium.fireEvent("name=field1", "blur");
51 Assert.assertEquals("true", selenium.getAttribute("name=field1@aria-invalid"));
52 Assert.assertTrue(selenium.getAttribute("name=field1@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
53 Assert.assertTrue(selenium.isElementPresent("//textarea[@name='field1']/../img[@alt='Error']"));
54 selenium.fireEvent("name=field1", "focus");
55 for (int second = 0; ; second++) {
56 if (second >= 60) {
57 Assert.fail("timeout");
58 }
59 try {
60 if (selenium.isVisible("css=.jquerybubblepopup-innerHtml")) {
61 break;
62 }
63 } catch (Exception e) {
64 }
65 Thread.sleep(1000);
66 }
67
68 Assert.assertTrue(selenium.isVisible(
69 "css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field"));
70 selenium.type("name=field1", "a");
71 selenium.keyDown("name=field1", "b");
72 selenium.keyUp("name=field1", "b");
73 for (int second = 0; ; second++) {
74 if (second >= 60) {
75 Assert.fail("timeout");
76 }
77 try {
78 if (!selenium.isVisible("css=.jquerybubblepopup-innerHtml")) {
79 break;
80 }
81 } catch (Exception e) {
82 }
83 Thread.sleep(1000);
84 }
85
86 Assert.assertFalse(selenium.isVisible("css=.jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
87 selenium.fireEvent("name=field1", "blur");
88 Assert.assertFalse(selenium.isElementPresent("name=field1@aria-invalid"));
89 Assert.assertTrue(selenium.getAttribute("name=field1@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
90 Assert.assertFalse(selenium.isElementPresent("//textarea[@name='field1']/../img[@alt='Error']"));
91 selenium.fireEvent("name=field2", "focus");
92 selenium.type("name=field2", "");
93 selenium.fireEvent("name=field2", "blur");
94 Assert.assertEquals("true", selenium.getAttribute("name=field2@aria-invalid"));
95 Assert.assertTrue(selenium.getAttribute("name=field2@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
96 Assert.assertTrue(selenium.isElementPresent("//input[@name='field2']/../img[@alt='Error']"));
97 selenium.fireEvent("name=field2", "focus");
98 selenium.type("name=field2", "a");
99 selenium.fireEvent("name=field2", "blur");
100 Assert.assertFalse(selenium.isElementPresent("name=field2@aria-invalid"));
101 Assert.assertTrue(selenium.getAttribute("name=field2@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
102 Assert.assertFalse(selenium.isElementPresent("//textarea[@name='field2']/../img[@alt='Error']"));
103 selenium.fireEvent("name=field3", "focus");
104 selenium.select("name=field3", "");
105 selenium.fireEvent("name=field3", "blur");
106 Assert.assertEquals("true", selenium.getAttribute("name=field3@aria-invalid"));
107 Assert.assertTrue(selenium.getAttribute("name=field3@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
108 Assert.assertTrue(selenium.isElementPresent("//select[@name='field3']/../img[@alt='Error']"));
109 selenium.fireEvent("name=field3", "focus");
110 selenium.select("name=field3", "Option 1");
111 selenium.fireEvent("name=field3", "blur");
112 Assert.assertFalse(selenium.isElementPresent("name=field3@aria-invalid"));
113 Assert.assertTrue(selenium.getAttribute("name=field3@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
114 Assert.assertFalse(selenium.isElementPresent("//select[@name='field3']/../img[@alt='Error']"));
115 selenium.fireEvent("name=field4", "focus");
116 selenium.removeAllSelections("name=field4");
117 selenium.fireEvent("name=field4", "blur");
118 Assert.assertEquals("true", selenium.getAttribute("name=field4@aria-invalid"));
119 Assert.assertTrue(selenium.getAttribute("name=field4@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
120 Assert.assertTrue(selenium.isElementPresent("//select[@name='field4']/../img[@alt='Error']"));
121 selenium.fireEvent("name=field4", "focus");
122 selenium.select("name=field4", "Option 1");
123 selenium.fireEvent("name=field4", "blur");
124 Assert.assertFalse(selenium.isElementPresent("name=field4@aria-invalid"));
125 Assert.assertTrue(selenium.getAttribute("name=field4@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
126 Assert.assertFalse(selenium.isElementPresent("//select[@name='field4']/../img[@alt='Error']"));
127 selenium.fireEvent("name=field117 value=3", "focus");
128 selenium.uncheck("name=field117 value=3");
129 selenium.fireEvent("name=field117", "blur");
130 for (int second = 0; ; second++) {
131 if (second >= 60) {
132 Assert.fail("timeout");
133 }
134 try {
135 if (selenium.isElementPresent("//input[@name='field117']/../../../img[@alt='Error']")) {
136 break;
137 }
138 } catch (Exception e) {
139 }
140 Thread.sleep(1000);
141 }
142
143 Assert.assertEquals("true", selenium.getAttribute("name=field117 value=1@aria-invalid"));
144 Assert.assertTrue(selenium.getAttribute("name=field117 value=1@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
145 Assert.assertTrue(selenium.isElementPresent("//input[@name='field117']/../../../img[@alt='Error']"));
146 selenium.fireEvent("name=field117 value=3", "focus");
147 selenium.check("name=field117 value=3");
148 selenium.fireEvent("name=field117 value=3", "blur");
149 for (int second = 0; ; second++) {
150 if (second >= 60) {
151 Assert.fail("timeout");
152 }
153 try {
154 if (!selenium.isElementPresent("//input[@name='field117']/../../../img[@alt='Error']")) {
155 break;
156 }
157 } catch (Exception e) {
158 }
159 Thread.sleep(1000);
160 }
161
162 Assert.assertFalse(selenium.isElementPresent("name=field117 value=1@aria-invalid"));
163 Assert.assertTrue(selenium.getAttribute("name=field117 value=3@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
164 Assert.assertFalse(selenium.isElementPresent("//input[@name='field117']/../../../img[@alt='Error']"));
165 selenium.fireEvent("name=bField1", "focus");
166 selenium.uncheck("name=bField1");
167 selenium.fireEvent("name=bField1", "blur");
168 Assert.assertEquals("true", selenium.getAttribute("name=bField1@aria-invalid"));
169 Assert.assertTrue(selenium.getAttribute("name=bField1@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
170 Assert.assertTrue(selenium.isElementPresent(
171 "//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
172 selenium.fireEvent("name=bField1", "focus");
173 selenium.check("name=bField1");
174 selenium.fireEvent("name=bField1", "blur");
175 Assert.assertFalse(selenium.isElementPresent("name=bField1@aria-invalid"));
176 Assert.assertTrue(selenium.getAttribute("name=bField1@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
177 Assert.assertFalse(selenium.isElementPresent(
178 "//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
179 selenium.fireEvent("name=field114 value=3", "focus");
180 selenium.uncheck("name=field114 value=3");
181 selenium.uncheck("name=field114 value=4");
182 selenium.fireEvent("name=field114", "blur");
183 for (int second = 0; ; second++) {
184 if (second >= 60) {
185 Assert.fail("timeout");
186 }
187 try {
188 if (selenium.isElementPresent("//input[@name='field114']/../../../img[@alt='Error']")) {
189 break;
190 }
191 } catch (Exception e) {
192 }
193 Thread.sleep(1000);
194 }
195
196 Assert.assertEquals("true", selenium.getAttribute("name=field114 value=1@aria-invalid"));
197 Assert.assertTrue(selenium.getAttribute("name=field114 value=1@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
198 Assert.assertTrue(selenium.isElementPresent("//input[@name='field114']/../../../img[@alt='Error']"));
199 selenium.fireEvent("name=field114 value=3", "focus");
200 selenium.check("name=field114 value=3");
201 selenium.check("name=field114 value=4");
202 selenium.fireEvent("name=field114", "blur");
203 for (int second = 0; ; second++) {
204 if (second >= 60) {
205 Assert.fail("timeout");
206 }
207 try {
208 if (!selenium.isElementPresent("//input[@name='field114']/../../../img[@alt='Error']")) {
209 break;
210 }
211 } catch (Exception e) {
212 }
213 Thread.sleep(1000);
214 }
215
216 Assert.assertFalse(selenium.isElementPresent("name=field114 value=1@aria-invalid"));
217 Assert.assertFalse(selenium.isElementPresent("//input[@name='field114']/../../../img[@alt='Error']"));
218 }
219
220 @After
221 public void tearDown() throws Exception {
222 selenium.stop();
223 }
224 }