View Javadoc

1   /*
2    * Copyright 2005-2013 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.SeleneseTestBase;
20  import edu.samplu.common.Failable;
21  import edu.samplu.common.ITUtil;
22  import edu.samplu.common.WebDriverLegacyITBase;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public abstract class ConstraintsAbstractSmokeTestBase extends WebDriverLegacyITBase {
28  
29      /**
30       * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3
31       */
32      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3";
33  
34      /**
35       * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}.  Bookmark Tests should override and return {@link ConstraintsAbstractSmokeTestBase#BOOKMARK_URL}
36       * {@inheritDoc}
37       * @return
38       */
39      @Override
40      public String getTestUrl() {
41          return ITUtil.PORTAL;
42      }
43  
44      protected void navigation() throws Exception {
45          waitAndClickKRAD();
46          waitAndClickByXpath(KITCHEN_SINK_XPATH);
47          switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
48          waitAndClickByLinkText("Validation");
49      }
50  
51      protected void testConstraintsNav(Failable failable) throws Exception {
52          navigation();
53          testConstraints();
54          passed();
55      }
56  
57      protected void testConstraintsBookmark(Failable failable) throws Exception {
58          testConstraints();
59          passed();
60      }
61  
62      protected void testConstraintsField9Nav(Failable failable) throws Exception {
63          navigation();
64          testField9FocusBlur();
65          passed();
66      }
67  
68      protected void testConstraintsField9Bookmark(Failable failable) throws Exception {
69          testField9FocusBlur();
70          passed();
71      }
72  
73      private void testField9FocusBlur() throws InterruptedException {
74          fireEvent("field9", "focus");
75          waitAndTypeByName("field9", "1");
76          fireEvent("field9", "blur");
77          assertAttributeClassRegexMatches("field9", REGEX_ERROR); // Sometimes get a failure here.
78  
79          fireEvent("field9", "focus");
80          clearTextByName("field9");
81          waitAndTypeByName("field9", "12345");
82          fireEvent("field9", "blur");
83          assertAttributeClassRegexMatches("field9", REGEX_VALID);
84      }
85  
86      protected void testConstraints() throws Exception {
87          checkForIncidentReport("testConstraints");
88  
89          // TODO break out into smaller methods, especially if a test flaps.
90          fireEvent("field10", "focus");
91          waitAndTypeByName("field10", "2");
92          fireEvent("field10", "blur");
93          assertAttributeClassRegexMatches("field10", REGEX_ERROR);
94  
95          fireEvent("field10", "focus");
96          clearTextByName("field10");
97          waitAndTypeByName("field10", "51");
98          fireEvent("field10", "blur");
99          assertAttributeClassRegexMatches("field10", REGEX_ERROR);
100 
101         fireEvent("field10", "focus");
102         clearTextByName("field10");
103         waitAndTypeByName("field10", "25");
104         fireEvent("field10", "blur");
105         assertAttributeClassRegexMatches("field10", REGEX_VALID);
106 
107         fireEvent("field6", "focus");
108         waitAndTypeByName("field6", "A");
109         fireEvent("field6", "blur");
110         waitAndTypeByName("field7", "");
111         fireEvent("field7", "blur");
112         assertAttributeClassRegexMatches("field7", REGEX_ERROR);
113 
114         waitAndTypeByName("field7", "B");
115         fireEvent("field7", "blur");
116         assertAttributeClassRegexMatches("field7", REGEX_VALID);
117 
118         waitAndTypeByName("field8", "");
119         fireEvent("field8", "blur");
120         assertAttributeClassRegexMatches("field8", REGEX_ERROR);
121 
122         clearTextByName("field8");
123         waitAndTypeByName("field8", "C");
124         fireEvent("field8", "blur");
125         assertAttributeClassRegexMatches("field8", REGEX_VALID);
126 
127         clearTextByName("field6");
128         waitAndTypeByName("field6", "");
129         fireEvent("field6", "blur");
130         assertAttributeClassRegexMatches("field6", REGEX_ERROR);
131 
132         clearTextByName("field7");
133         waitAndTypeByName("field7", "");
134         fireEvent("field7", "blur");
135         assertAttributeClassRegexMatches("field7", REGEX_VALID);
136 
137         clearTextByName("field8");
138         waitAndTypeByName("field8", "");
139         fireEvent("field8", "blur");
140         assertAttributeClassRegexMatches("field6", REGEX_VALID);
141         assertAttributeClassRegexMatches("field7", REGEX_VALID);
142         assertAttributeClassRegexMatches("field8", REGEX_VALID);
143 
144         clearTextByName("field8");
145         waitAndTypeByName("field8", "C");
146         fireEvent("field8", "blur");
147         assertAttributeClassRegexMatches("field6", REGEX_ERROR);
148         assertAttributeClassRegexMatches("field7", REGEX_VALID);
149         assertAttributeClassRegexMatches("field8", REGEX_ERROR);
150 
151         clearTextByName("field6");
152         waitAndTypeByName("field6", "A");
153         fireEvent("field6", "blur");
154         assertAttributeClassRegexMatches("field6", REGEX_VALID);
155         assertAttributeClassRegexMatches("field7", REGEX_ERROR);
156         assertAttributeClassRegexMatches("field8", REGEX_VALID);
157 
158         waitAndTypeByName("field14", "A");
159         fireEvent("field14", "blur");
160 
161         assertAttributeClassRegexMatches("field14", REGEX_ERROR);
162         clearTextByName("field11");
163         waitAndTypeByName("field11", "A");
164         fireEvent("field11", "blur");
165         assertAttributeClassRegexMatches("field11", REGEX_VALID);
166         assertAttributeClassRegexMatches("field14", REGEX_VALID);
167 
168         clearTextByName("field11");
169         waitAndTypeByName("field11", "");
170         fireEvent("field11", "blur");
171         assertAttributeClassRegexMatches("field14", REGEX_ERROR);
172 
173         clearTextByName("field12");
174         waitAndTypeByName("field12", "A");
175         fireEvent("field12", "blur");
176         assertAttributeClassRegexMatches("field14", REGEX_ERROR);
177 
178         clearTextByName("field13");
179         waitAndTypeByName("field13", "A");
180         fireEvent("field13", "blur");
181         assertAttributeClassRegexMatches("field13", REGEX_VALID);
182         assertAttributeClassRegexMatches("field14", REGEX_VALID);
183 
184         clearTextByName("field11");
185         waitAndTypeByName("field11", "A");
186         fireEvent("field11", "blur");
187         assertAttributeClassRegexMatches("field11", REGEX_VALID);
188         assertAttributeClassRegexMatches("field14", REGEX_VALID);
189 
190         waitAndTypeByName("field18", "A");
191         fireEvent("field18", "blur");
192         assertAttributeClassRegexMatches("field18", REGEX_ERROR);
193 
194         waitAndTypeByName("field15", "A");
195         fireEvent("field15", "blur");
196         assertAttributeClassRegexMatches("field15", REGEX_VALID);
197         assertAttributeClassRegexMatches("field18", REGEX_VALID);
198 
199         clearTextByName("field15");
200         waitAndTypeByName("field15", "");
201         fireEvent("field15", "blur");
202         assertAttributeClassRegexMatches("field18", REGEX_ERROR);
203 
204         clearTextByName("field6");
205         waitAndTypeByName("field16", "A");
206         fireEvent("field16", "blur");
207         assertAttributeClassRegexMatches("field18", REGEX_ERROR);
208 
209         clearTextByName("field17");
210         waitAndTypeByName("field17", "A");
211         fireEvent("field17", "blur");
212         assertAttributeClassRegexMatches("field17", REGEX_VALID);
213         assertAttributeClassRegexMatches("field18", REGEX_VALID);
214 
215         clearTextByName("field15");
216         waitAndTypeByName("field15", "A");
217         fireEvent("field15", "blur");
218         assertAttributeClassRegexMatches("field18", REGEX_ERROR);
219 
220         waitAndTypeByName("field23", "A");
221         fireEvent("field23", "blur");
222         assertAttributeClassRegexMatches("field23", REGEX_ERROR);
223 
224         clearTextByName("field19");
225         waitAndTypeByName("field19", "A");
226         fireEvent("field19", "blur");
227         assertAttributeClassRegexMatches("field23", REGEX_VALID);
228 
229         clearTextByName("field19");
230         waitAndTypeByName("field19", "");
231         fireEvent("field19", "blur");
232         waitAndTypeByName("field20", "B");
233         fireEvent("field20", "blur");
234         assertAttributeClassRegexMatches("field23", REGEX_VALID);
235 
236         clearTextByName("field20");
237         waitAndTypeByName("field20", "");
238         fireEvent("field20", "blur");
239         assertAttributeClassRegexMatches("field23", REGEX_ERROR);
240 
241         clearTextByName("field21");
242         waitAndTypeByName("field21", "C");
243         fireEvent("field21", "blur");
244         assertAttributeClassRegexMatches("field23", REGEX_ERROR);
245 
246         clearTextByName("field22");
247         waitAndTypeByName("field22", "D");
248         fireEvent("field22", "blur");
249         assertAttributeClassRegexMatches("field23", REGEX_VALID);
250 
251         clearTextByName("field19");
252         waitAndTypeByName("field19", "D");
253         fireEvent("field19", "blur");
254         assertAttributeClassRegexMatches("field23", REGEX_VALID);
255 
256         clearTextByName("field20");
257         waitAndTypeByName("field20", "D");
258         fireEvent("field20", "blur");
259         assertAttributeClassRegexMatches("field23", REGEX_VALID);
260 
261         checkByXpath("//*[@name='field24' and @value='case1']");
262         clearTextByName("field25");
263         waitAndTypeByName("field25", "");
264         fireEvent("field25", "blur");
265         assertAttributeClassRegexMatches("field25", REGEX_ERROR);
266 
267         checkByXpath("//*[@name='field24' and @value='case4']");
268         fireEvent("field24", "blur");
269 
270         for (int second = 0;; second++) {
271             if (second >= waitSeconds) {
272                 SeleneseTestBase.fail("timeout");
273             }
274             try {
275                 if (getAttributeByName("field25", "class").matches(REGEX_VALID)) {
276                     break;
277                 }
278             } catch (Exception e) {}
279             Thread.sleep(1000);
280         }
281 
282         assertAttributeClassRegexMatches("field25", REGEX_VALID);
283 
284         checkByXpath("//*[@name='field24' and @value='case1']");
285         fireEvent("field24", "blur");
286         clearTextByName("field25");
287         waitAndTypeByName("field25", "$100");
288         fireEvent("field25", "blur");
289 
290         for (int second = 0;; second++) {
291             if (second >= waitSeconds) {
292                 SeleneseTestBase.fail("timeout");
293             }
294             try {
295                 if (getAttributeByName("field25", "class").matches(REGEX_VALID)) {
296                     break;
297                 }
298             } catch (Exception e) {}
299             Thread.sleep(1000);
300         }
301 
302         assertAttributeClassRegexMatches("field25", REGEX_VALID);
303 
304         checkByXpath("//*[@name='field24' and @value='case2']");
305         fireEvent("field24", "blur");
306 
307         for (int second = 0;; second++) {
308             if (second >= waitSeconds) {
309                 SeleneseTestBase.fail("timeout");
310             }
311             try {
312                 if (getAttributeByName("field25", "class").matches(REGEX_ERROR)) {
313                     break;
314                 }
315             } catch (Exception e) {}
316             Thread.sleep(1000);
317         }
318 
319         assertAttributeClassRegexMatches("field25", REGEX_ERROR);
320 
321         clearTextByName("field25");
322         waitAndTypeByName("field25", "A100");
323         fireEvent("field25", "blur");
324         assertAttributeClassRegexMatches("field25", REGEX_VALID);
325 
326         checkByXpath("//*[@name='field24' and @value='case3']");
327         fireEvent("field24", "blur");
328         clearTextByName("field26");
329         waitAndTypeByName("field26", "6000");
330         fireEvent("field26", "blur");
331 
332         for (int second = 0;; second++) {
333             if (second >= waitSeconds) {
334                 SeleneseTestBase.fail("timeout");
335             }
336             try {
337                 if (getAttributeByName("field26", "class").matches(REGEX_ERROR)) {
338                     break;
339                 }
340             } catch (Exception e) {}
341             Thread.sleep(1000);
342         }
343 
344         assertAttributeClassRegexMatches("field26", REGEX_ERROR);
345 
346         clearTextByName("field26");
347         waitAndTypeByName("field26", "501");
348         fireEvent("field26", "blur");
349         assertAttributeClassRegexMatches("field26", REGEX_ERROR);
350 
351         clearTextByName("field26");
352         waitAndTypeByName("field26", "499");
353         fireEvent("field26", "blur");
354         assertAttributeClassRegexMatches("field26", REGEX_VALID);
355 
356         clearTextByName("field26");
357         waitAndTypeByName("field26", "6000");
358         fireEvent("field26", "blur");
359         checkByXpath("//*[@name='field24' and @value='case3']");
360         fireEvent("field24", "blur");
361 
362         for (int second = 0;; second++) {
363             if (second >= waitSeconds) {
364                 SeleneseTestBase.fail("timeout");
365             }
366             try {
367                 if (getAttributeByName("field26", "class").matches(REGEX_ERROR)) {
368                     break;
369                 }
370             } catch (Exception e) {}
371             Thread.sleep(1000);
372         }
373 
374         assertAttributeClassRegexMatches("field26", REGEX_ERROR);
375 
376         checkByXpath("//*[@name='field24' and @value='case4']");
377         clearTextByName("field27");
378         waitAndTypeByName("field27", "A");
379         fireEvent("field27", "blur");
380         clearTextByName("field28");
381         waitAndTypeByName("field28", "");
382         fireEvent("field28", "blur");
383 
384         for (int second = 0;; second++) {
385             if (second >= waitSeconds) {
386                 SeleneseTestBase.fail("timeout");
387             }
388             try {
389                 if (getAttributeByName("field28", "class").matches(REGEX_ERROR)) {
390                     break;
391                 }
392             } catch (Exception e) {}
393             Thread.sleep(1000);
394         }
395 
396         assertAttributeClassRegexMatches("field28", REGEX_ERROR);
397 
398         checkByXpath("//*[@name='field24' and @value='case3']");
399         fireEvent("field24", "blur");
400 
401         for (int second = 0;; second++) {
402             if (second >= waitSeconds) {
403                 SeleneseTestBase.fail("timeout");
404             }
405             try {
406                 if (getAttributeByName("field28", "class").matches(REGEX_VALID)) {
407                     break;
408                 }
409             } catch (Exception e) {}
410             Thread.sleep(1000);
411         }
412 
413         assertAttributeClassRegexMatches("field28", REGEX_VALID);
414 
415         clearTextByName("field28");
416         waitAndTypeByName("field28", "B");
417         fireEvent("field28", "blur");
418         checkByXpath("//*[@name='field24' and @value='case4']");
419         fireEvent("field24", "blur");
420 
421         for (int second = 0;; second++) {
422             if (second >= waitSeconds) {
423                 SeleneseTestBase.fail("timeout");
424             }
425             try {
426                 if (getAttributeByName("field28", "class").matches(REGEX_VALID)) {
427                     break;
428                 }
429             } catch (Exception e) {}
430             Thread.sleep(1000);
431         }
432 
433         assertAttributeClassRegexMatches("field28", REGEX_VALID);
434 
435         clearTextByName("field31");
436         waitAndTypeByName("field31", "B");
437         clearTextByName("field32");
438         waitAndTypeByName("field32", "B");
439         waitAndTypeByName("field33", "");
440         fireEvent("field33", "blur");
441         assertAttributeClassRegexMatches("field33", REGEX_ERROR);
442 
443         clearTextByName("field33");
444         waitAndTypeByName("field33", "B");
445         fireEvent("field33", "blur");
446         assertAttributeClassRegexMatches("field33", REGEX_VALID);
447 
448         clearTextByName("field32");
449         waitAndTypeByName("field32", "A");
450         clearTextByName("field33");
451         waitAndTypeByName("field33", "");
452         fireEvent("field33", "blur");
453         assertAttributeClassRegexMatches("field33", REGEX_VALID);
454     }
455 }