001    /*
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package edu.samplu.krad.compview;
018    
019    import com.thoughtworks.selenium.SeleneseTestBase;
020    import edu.samplu.common.Failable;
021    import edu.samplu.common.ITUtil;
022    import edu.samplu.common.WebDriverLegacyITBase;
023    
024    /**
025     * @author Kuali Rice Team (rice.collab@kuali.org)
026     */
027    public abstract class ConstraintsAbstractSmokeTestBase extends WebDriverLegacyITBase {
028    
029        /**
030         * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3
031         */
032        public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3";
033    
034        /**
035         * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}.  Bookmark Tests should override and return {@link ConstraintsAbstractSmokeTestBase#BOOKMARK_URL}
036         * {@inheritDoc}
037         * @return
038         */
039        @Override
040        public String getTestUrl() {
041            return ITUtil.PORTAL;
042        }
043    
044        protected void navigation() throws Exception {
045            waitAndClickKRAD();
046            waitAndClickByXpath(KITCHEN_SINK_XPATH);
047            switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
048            waitAndClickByLinkText("Validation");
049        }
050    
051        protected void testConstraintsNav(Failable failable) throws Exception {
052            navigation();
053            testConstraints();
054            passed();
055        }
056    
057        protected void testConstraintsBookmark(Failable failable) throws Exception {
058            testConstraints();
059            passed();
060        }
061    
062        protected void testConstraintsField9Nav(Failable failable) throws Exception {
063            navigation();
064            testField9FocusBlur();
065            passed();
066        }
067    
068        protected void testConstraintsField9Bookmark(Failable failable) throws Exception {
069            testField9FocusBlur();
070            passed();
071        }
072    
073        private void testField9FocusBlur() throws InterruptedException {
074            fireEvent("field9", "focus");
075            waitAndTypeByName("field9", "1");
076            fireEvent("field9", "blur");
077            assertAttributeClassRegexMatches("field9", REGEX_ERROR); // Sometimes get a failure here.
078    
079            fireEvent("field9", "focus");
080            clearTextByName("field9");
081            waitAndTypeByName("field9", "12345");
082            fireEvent("field9", "blur");
083            assertAttributeClassRegexMatches("field9", REGEX_VALID);
084        }
085    
086        protected void testConstraints() throws Exception {
087            checkForIncidentReport("testConstraints");
088    
089            // TODO break out into smaller methods, especially if a test flaps.
090            fireEvent("field10", "focus");
091            waitAndTypeByName("field10", "2");
092            fireEvent("field10", "blur");
093            assertAttributeClassRegexMatches("field10", REGEX_ERROR);
094    
095            fireEvent("field10", "focus");
096            clearTextByName("field10");
097            waitAndTypeByName("field10", "51");
098            fireEvent("field10", "blur");
099            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    }