View Javadoc

1   /*
2    * Copyright 2006-2012 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  
17  package edu.samplu.krad.compview;
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 ContraintsIT {
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=UifCompView&methodToCall=start&pageId=UifCompView-Page3");
36  
37          // Login
38          selenium.open(
39                  "http://localhost:8080/kr-dev/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3");
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 testContraintsIT() throws Exception {
48          selenium.focus("name=field9");
49          selenium.type("name=field9", "1");
50          selenium.fireEvent("name=field9", "blur");
51          Assert.assertTrue(selenium.getAttribute("name=field9@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
52          selenium.focus("name=field9");
53          selenium.type("name=field9", "12345");
54          selenium.fireEvent("name=field9", "blur");
55          Assert.assertTrue(selenium.getAttribute("name=field9@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
56          selenium.focus("name=field10");
57          selenium.type("name=field10", "2");
58          selenium.fireEvent("name=field10", "blur");
59          Assert.assertTrue(selenium.getAttribute("name=field10@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
60          selenium.focus("name=field10");
61          selenium.type("name=field10", "51");
62          selenium.fireEvent("name=field10", "blur");
63          Assert.assertTrue(selenium.getAttribute("name=field10@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
64          selenium.focus("name=field10");
65          selenium.type("name=field10", "25");
66          selenium.fireEvent("name=field10", "blur");
67          Assert.assertTrue(selenium.getAttribute("name=field10@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
68          selenium.focus("name=field6");
69          selenium.type("name=field6", "A");
70          selenium.fireEvent("name=field6", "blur");
71          selenium.fireEvent("name=field7", "blur");
72          Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
73          selenium.type("name=field7", "B");
74          selenium.fireEvent("name=field7", "blur");
75          Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
76          selenium.fireEvent("name=field8", "blur");
77          Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
78          selenium.type("name=field8", "C");
79          selenium.fireEvent("name=field8", "blur");
80          Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
81          selenium.type("name=field6", "");
82          selenium.fireEvent("name=field6", "blur");
83          Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
84          selenium.type("name=field7", "");
85          selenium.fireEvent("name=field7", "blur");
86          Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
87          selenium.type("name=field8", "");
88          selenium.fireEvent("name=field8", "blur");
89          Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
90          Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
91          Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
92          selenium.type("name=field8", "C");
93          selenium.fireEvent("name=field8", "blur");
94          Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
95          Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
96          Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
97          selenium.type("name=field6", "A");
98          selenium.fireEvent("name=field6", "blur");
99          Assert.assertTrue(selenium.getAttribute("name=field6@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
100         Assert.assertTrue(selenium.getAttribute("name=field7@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
101         Assert.assertTrue(selenium.getAttribute("name=field8@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
102         selenium.type("name=field14", "A");
103         selenium.fireEvent("name=field14", "blur");
104         Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
105         selenium.type("name=field11", "A");
106         selenium.fireEvent("name=field11", "blur");
107         Assert.assertTrue(selenium.getAttribute("name=field11@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
108         Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
109         selenium.type("name=field11", "");
110         selenium.fireEvent("name=field11", "blur");
111         Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
112         selenium.type("name=field12", "A");
113         selenium.fireEvent("name=field12", "blur");
114         Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
115         selenium.type("name=field13", "A");
116         selenium.fireEvent("name=field13", "blur");
117         Assert.assertTrue(selenium.getAttribute("name=field13@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
118         Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
119         selenium.type("name=field11", "A");
120         selenium.fireEvent("name=field11", "blur");
121         Assert.assertTrue(selenium.getAttribute("name=field11@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
122         Assert.assertTrue(selenium.getAttribute("name=field14@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
123         selenium.type("name=field18", "A");
124         selenium.fireEvent("name=field18", "blur");
125         Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
126         selenium.type("name=field15", "A");
127         selenium.fireEvent("name=field15", "blur");
128         Assert.assertTrue(selenium.getAttribute("name=field15@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
129         Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
130         selenium.type("name=field15", "");
131         selenium.fireEvent("name=field15", "blur");
132         Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
133         selenium.type("name=field16", "A");
134         selenium.fireEvent("name=field16", "blur");
135         Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
136         selenium.type("name=field17", "A");
137         selenium.fireEvent("name=field17", "blur");
138         Assert.assertTrue(selenium.getAttribute("name=field17@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
139         Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
140         selenium.type("name=field15", "A");
141         selenium.fireEvent("name=field15", "blur");
142         Assert.assertTrue(selenium.getAttribute("name=field18@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
143         selenium.type("name=field23", "A");
144         selenium.fireEvent("name=field23", "blur");
145         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
146         selenium.type("name=field19", "A");
147         selenium.fireEvent("name=field19", "blur");
148         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
149         selenium.type("name=field19", "");
150         selenium.fireEvent("name=field19", "blur");
151         selenium.type("name=field20", "B");
152         selenium.fireEvent("name=field20", "blur");
153         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
154         selenium.type("name=field20", "");
155         selenium.fireEvent("name=field20", "blur");
156         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
157         selenium.type("name=field21", "C");
158         selenium.fireEvent("name=field21", "blur");
159         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
160         selenium.type("name=field22", "D");
161         selenium.fireEvent("name=field22", "blur");
162         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
163         selenium.type("name=field19", "D");
164         selenium.fireEvent("name=field19", "blur");
165         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
166         selenium.type("name=field20", "D");
167         selenium.fireEvent("name=field20", "blur");
168         Assert.assertTrue(selenium.getAttribute("name=field23@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
169         selenium.check("name=field24 value=case1");
170         selenium.type("name=field25", "");
171         selenium.fireEvent("name=field25", "blur");
172         Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
173         selenium.check("name=field24 value=case4");
174         selenium.fireEvent("name=field24", "blur");
175         for (int second = 0; ; second++) {
176             if (second >= 60) {
177                 Assert.fail("timeout");
178             }
179             try {
180                 if (selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
181                     break;
182                 }
183             } catch (Exception e) {
184             }
185             Thread.sleep(1000);
186         }
187 
188         Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
189         selenium.check("name=field24 value=case1");
190         selenium.fireEvent("name=field24", "blur");
191         selenium.type("name=field25", "$100");
192         selenium.fireEvent("name=field25", "blur");
193         for (int second = 0; ; second++) {
194             if (second >= 60) {
195                 Assert.fail("timeout");
196             }
197             try {
198                 if (selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
199                     break;
200                 }
201             } catch (Exception e) {
202             }
203             Thread.sleep(1000);
204         }
205 
206         Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
207         selenium.check("name=field24 value=case2");
208         selenium.fireEvent("name=field24", "blur");
209         for (int second = 0; ; second++) {
210             if (second >= 60) {
211                 Assert.fail("timeout");
212             }
213             try {
214                 if (selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
215                     break;
216                 }
217             } catch (Exception e) {
218             }
219             Thread.sleep(1000);
220         }
221 
222         Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
223         selenium.type("name=field25", "A100");
224         selenium.fireEvent("name=field25", "blur");
225         Assert.assertTrue(selenium.getAttribute("name=field25@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
226         selenium.check("name=field24 value=case3");
227         selenium.fireEvent("name=field24", "blur");
228         selenium.type("name=field26", "6000");
229         selenium.fireEvent("name=field26", "blur");
230         for (int second = 0; ; second++) {
231             if (second >= 60) {
232                 Assert.fail("timeout");
233             }
234             try {
235                 if (selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
236                     break;
237                 }
238             } catch (Exception e) {
239             }
240             Thread.sleep(1000);
241         }
242 
243         Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
244         selenium.type("name=field26", "501");
245         selenium.fireEvent("name=field26", "blur");
246         Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
247         selenium.type("name=field26", "499");
248         selenium.fireEvent("name=field26", "blur");
249         Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
250         selenium.type("name=field26", "6000");
251         selenium.fireEvent("name=field26", "blur");
252         selenium.check("name=field24 value=case3");
253         selenium.fireEvent("name=field24", "blur");
254         for (int second = 0; ; second++) {
255             if (second >= 60) {
256                 Assert.fail("timeout");
257             }
258             try {
259                 if (selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
260                     break;
261                 }
262             } catch (Exception e) {
263             }
264             Thread.sleep(1000);
265         }
266 
267         Assert.assertTrue(selenium.getAttribute("name=field26@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
268         selenium.check("name=field24 value=case4");
269         selenium.type("name=field27", "A");
270         selenium.fireEvent("name=field27", "blur");
271         selenium.type("name=field28", "");
272         selenium.fireEvent("name=field28", "blur");
273         for (int second = 0; ; second++) {
274             if (second >= 60) {
275                 Assert.fail("timeout");
276             }
277             try {
278                 if (selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*error[\\s\\S]*$")) {
279                     break;
280                 }
281             } catch (Exception e) {
282             }
283             Thread.sleep(1000);
284         }
285 
286         Assert.assertTrue(selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
287         selenium.check("name=field24 value=case3");
288         selenium.fireEvent("name=field24", "blur");
289         for (int second = 0; ; second++) {
290             if (second >= 60) {
291                 Assert.fail("timeout");
292             }
293             try {
294                 if (selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
295                     break;
296                 }
297             } catch (Exception e) {
298             }
299             Thread.sleep(1000);
300         }
301 
302         Assert.assertTrue(selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
303         selenium.type("name=field28", "B");
304         selenium.fireEvent("name=field28", "blur");
305         selenium.check("name=field24 value=case4");
306         selenium.fireEvent("name=field24", "blur");
307         for (int second = 0; ; second++) {
308             if (second >= 60) {
309                 Assert.fail("timeout");
310             }
311             try {
312                 if (selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$")) {
313                     break;
314                 }
315             } catch (Exception e) {
316             }
317             Thread.sleep(1000);
318         }
319 
320         Assert.assertTrue(selenium.getAttribute("name=field28@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
321         selenium.type("name=field31", "B");
322         selenium.type("name=field32", "B");
323         selenium.fireEvent("name=field33", "blur");
324         Assert.assertTrue(selenium.getAttribute("name=field33@class").matches("^[\\s\\S]*error[\\s\\S]*$"));
325         selenium.type("name=field33", "B");
326         selenium.fireEvent("name=field33", "blur");
327         Assert.assertTrue(selenium.getAttribute("name=field33@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
328         selenium.type("name=field32", "A");
329         selenium.type("name=field33", "");
330         selenium.fireEvent("name=field33", "blur");
331         Assert.assertTrue(selenium.getAttribute("name=field33@class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
332     }
333 
334     @After
335     public void tearDown() throws Exception {
336         selenium.stop();
337     }
338 }