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        protected void testPreRequisiteConstraintNav(Failable failable) throws Exception {
074            navigation();
075            testPreRequisiteConstraint();
076            passed();
077        }
078    
079        protected void testPreRequisiteConstraintBookmark(Failable failable) throws Exception {
080            testPreRequisiteConstraint();
081            passed();
082        }
083    
084        private void testPreRequisiteConstraint() throws Exception {
085            fireEvent("field6", "focus");
086            waitAndTypeByName("field6", "A");
087            fireEvent("field6", "blur");
088            waitAndTypeByName("field7", "");
089            fireEvent("field7", "blur");
090            assertAttributeClassRegexMatches("field7", REGEX_ERROR);
091    
092            waitAndTypeByName("field7", "B");
093            fireEvent("field7", "blur");
094            assertAttributeClassRegexMatches("field7", REGEX_VALID);
095    
096            waitAndTypeByName("field8", "");
097            fireEvent("field8", "blur");
098            assertAttributeClassRegexMatches("field8", REGEX_ERROR);
099    
100            clearTextByName("field8");
101            waitAndTypeByName("field8", "C");
102            fireEvent("field8", "blur");
103            assertAttributeClassRegexMatches("field8", REGEX_VALID);
104    
105            clearTextByName("field6");
106            waitAndTypeByName("field6", "");
107            fireEvent("field6", "blur");
108            assertAttributeClassRegexMatches("field6", REGEX_ERROR);
109    
110            clearTextByName("field7");
111            waitAndTypeByName("field7", "");
112            fireEvent("field7", "blur");
113            assertAttributeClassRegexMatches("field7", REGEX_VALID);
114    
115            clearTextByName("field8");
116            waitAndTypeByName("field8", "");
117            fireEvent("field8", "blur");
118            assertAttributeClassRegexMatches("field6", REGEX_VALID);
119            assertAttributeClassRegexMatches("field7", REGEX_VALID);
120            assertAttributeClassRegexMatches("field8", REGEX_VALID);
121    
122            clearTextByName("field8");
123            waitAndTypeByName("field8", "C");
124            fireEvent("field8", "blur");
125            assertAttributeClassRegexMatches("field6", REGEX_ERROR);
126            assertAttributeClassRegexMatches("field7", REGEX_VALID);
127            assertAttributeClassRegexMatches("field8", REGEX_ERROR);
128    
129            clearTextByName("field6");
130            waitAndTypeByName("field6", "A");
131            fireEvent("field6", "blur");
132            assertAttributeClassRegexMatches("field6", REGEX_VALID);
133            assertAttributeClassRegexMatches("field7", REGEX_ERROR);
134            assertAttributeClassRegexMatches("field8", REGEX_VALID);
135            passed();
136        }
137    
138        private void testField9FocusBlur() throws InterruptedException {
139            fireEvent("field9", "focus");
140            waitAndTypeByName("field9", "1");
141            fireEvent("field9", "blur");
142            assertAttributeClassRegexMatches("field9", REGEX_ERROR); // Sometimes get a failure here.
143    
144            fireEvent("field9", "focus");
145            clearTextByName("field9");
146            waitAndTypeByName("field9", "12345");
147            fireEvent("field9", "blur");
148            assertAttributeClassRegexMatches("field9", REGEX_VALID);
149        }
150    
151        protected void testConstraints() throws Exception {
152            checkForIncidentReport("testConstraints");
153    
154            // TODO break out into smaller methods, especially if a test flaps. https://jira.kuali.org/browse/KULRICE-9711
155            fireEvent("field10", "focus");
156            waitAndTypeByName("field10", "2");
157            fireEvent("field10", "blur");
158            assertAttributeClassRegexMatches("field10", REGEX_ERROR);
159    
160            fireEvent("field10", "focus");
161            clearTextByName("field10");
162            waitAndTypeByName("field10", "51");
163            fireEvent("field10", "blur");
164            assertAttributeClassRegexMatches("field10", REGEX_ERROR);
165    
166            fireEvent("field10", "focus");
167            clearTextByName("field10");
168            waitAndTypeByName("field10", "25");
169            fireEvent("field10", "blur");
170            assertAttributeClassRegexMatches("field10", REGEX_VALID);
171    
172            waitAndTypeByName("field14", "A");
173            fireEvent("field14", "blur");
174    
175            assertAttributeClassRegexMatches("field14", REGEX_ERROR);
176            clearTextByName("field11");
177            waitAndTypeByName("field11", "A");
178            fireEvent("field11", "blur");
179            assertAttributeClassRegexMatches("field11", REGEX_VALID);
180            assertAttributeClassRegexMatches("field14", REGEX_VALID);
181    
182            clearTextByName("field11");
183            waitAndTypeByName("field11", "");
184            fireEvent("field11", "blur");
185            assertAttributeClassRegexMatches("field14", REGEX_ERROR);
186    
187            clearTextByName("field12");
188            waitAndTypeByName("field12", "A");
189            fireEvent("field12", "blur");
190            assertAttributeClassRegexMatches("field14", REGEX_ERROR);
191    
192            clearTextByName("field13");
193            waitAndTypeByName("field13", "A");
194            fireEvent("field13", "blur");
195            assertAttributeClassRegexMatches("field13", REGEX_VALID);
196            assertAttributeClassRegexMatches("field14", REGEX_VALID);
197    
198            clearTextByName("field11");
199            waitAndTypeByName("field11", "A");
200            fireEvent("field11", "blur");
201            assertAttributeClassRegexMatches("field11", REGEX_VALID);
202            assertAttributeClassRegexMatches("field14", REGEX_VALID);
203    
204            waitAndTypeByName("field18", "A");
205            fireEvent("field18", "blur");
206            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
207    
208            waitAndTypeByName("field15", "A");
209            fireEvent("field15", "blur");
210            assertAttributeClassRegexMatches("field15", REGEX_VALID);
211            assertAttributeClassRegexMatches("field18", REGEX_VALID);
212    
213            clearTextByName("field15");
214            waitAndTypeByName("field15", "");
215            fireEvent("field15", "blur");
216            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
217    
218            clearTextByName("field6");
219            waitAndTypeByName("field16", "A");
220            fireEvent("field16", "blur");
221            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
222    
223            clearTextByName("field17");
224            waitAndTypeByName("field17", "A");
225            fireEvent("field17", "blur");
226            assertAttributeClassRegexMatches("field17", REGEX_VALID);
227            assertAttributeClassRegexMatches("field18", REGEX_VALID);
228    
229            clearTextByName("field15");
230            waitAndTypeByName("field15", "A");
231            fireEvent("field15", "blur");
232            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
233    
234            waitAndTypeByName("field23", "A");
235            fireEvent("field23", "blur");
236            assertAttributeClassRegexMatches("field23", REGEX_ERROR);
237    
238            clearTextByName("field19");
239            waitAndTypeByName("field19", "A");
240            fireEvent("field19", "blur");
241            assertAttributeClassRegexMatches("field23", REGEX_VALID);
242    
243            clearTextByName("field19");
244            waitAndTypeByName("field19", "");
245            fireEvent("field19", "blur");
246            waitAndTypeByName("field20", "B");
247            fireEvent("field20", "blur");
248            assertAttributeClassRegexMatches("field23", REGEX_VALID);
249    
250            clearTextByName("field20");
251            waitAndTypeByName("field20", "");
252            fireEvent("field20", "blur");
253            assertAttributeClassRegexMatches("field23", REGEX_ERROR);
254    
255            clearTextByName("field21");
256            waitAndTypeByName("field21", "C");
257            fireEvent("field21", "blur");
258            assertAttributeClassRegexMatches("field23", REGEX_ERROR);
259    
260            clearTextByName("field22");
261            waitAndTypeByName("field22", "D");
262            fireEvent("field22", "blur");
263            assertAttributeClassRegexMatches("field23", REGEX_VALID);
264    
265            clearTextByName("field19");
266            waitAndTypeByName("field19", "D");
267            fireEvent("field19", "blur");
268            assertAttributeClassRegexMatches("field23", REGEX_VALID);
269    
270            clearTextByName("field20");
271            waitAndTypeByName("field20", "D");
272            fireEvent("field20", "blur");
273            assertAttributeClassRegexMatches("field23", REGEX_VALID);
274    
275            checkByXpath("//*[@name='field24' and @value='case1']");
276            clearTextByName("field25");
277            waitAndTypeByName("field25", "");
278            fireEvent("field25", "blur");
279            assertAttributeClassRegexMatches("field25", REGEX_ERROR);
280    
281            checkByXpath("//*[@name='field24' and @value='case4']");
282            fireEvent("field24", "blur");
283    
284            for (int second = 0;; second++) {
285                if (second >= waitSeconds) {
286                    SeleneseTestBase.fail("timeout");
287                }
288                try {
289                    if (getAttributeByName("field25", "class").matches(REGEX_VALID)) {
290                        break;
291                    }
292                } catch (Exception e) {}
293                Thread.sleep(1000);
294            }
295    
296            assertAttributeClassRegexMatches("field25", REGEX_VALID);
297    
298            checkByXpath("//*[@name='field24' and @value='case1']");
299            fireEvent("field24", "blur");
300            clearTextByName("field25");
301            waitAndTypeByName("field25", "$100");
302            fireEvent("field25", "blur");
303    
304            for (int second = 0;; second++) {
305                if (second >= waitSeconds) {
306                    SeleneseTestBase.fail("timeout");
307                }
308                try {
309                    if (getAttributeByName("field25", "class").matches(REGEX_VALID)) {
310                        break;
311                    }
312                } catch (Exception e) {}
313                Thread.sleep(1000);
314            }
315    
316            assertAttributeClassRegexMatches("field25", REGEX_VALID);
317    
318            checkByXpath("//*[@name='field24' and @value='case2']");
319            fireEvent("field24", "blur");
320    
321            for (int second = 0;; second++) {
322                if (second >= waitSeconds) {
323                    SeleneseTestBase.fail("timeout");
324                }
325                try {
326                    if (getAttributeByName("field25", "class").matches(REGEX_ERROR)) {
327                        break;
328                    }
329                } catch (Exception e) {}
330                Thread.sleep(1000);
331            }
332    
333            assertAttributeClassRegexMatches("field25", REGEX_ERROR);
334    
335            clearTextByName("field25");
336            waitAndTypeByName("field25", "A100");
337            fireEvent("field25", "blur");
338            assertAttributeClassRegexMatches("field25", REGEX_VALID);
339    
340            checkByXpath("//*[@name='field24' and @value='case3']");
341            fireEvent("field24", "blur");
342            clearTextByName("field26");
343            waitAndTypeByName("field26", "6000");
344            fireEvent("field26", "blur");
345    
346            for (int second = 0;; second++) {
347                if (second >= waitSeconds) {
348                    SeleneseTestBase.fail("timeout");
349                }
350                try {
351                    if (getAttributeByName("field26", "class").matches(REGEX_ERROR)) {
352                        break;
353                    }
354                } catch (Exception e) {}
355                Thread.sleep(1000);
356            }
357    
358            assertAttributeClassRegexMatches("field26", REGEX_ERROR);
359    
360            clearTextByName("field26");
361            waitAndTypeByName("field26", "501");
362            fireEvent("field26", "blur");
363            assertAttributeClassRegexMatches("field26", REGEX_ERROR);
364    
365            clearTextByName("field26");
366            waitAndTypeByName("field26", "499");
367            fireEvent("field26", "blur");
368            assertAttributeClassRegexMatches("field26", REGEX_VALID);
369    
370            clearTextByName("field26");
371            waitAndTypeByName("field26", "6000");
372            fireEvent("field26", "blur");
373            checkByXpath("//*[@name='field24' and @value='case3']");
374            fireEvent("field24", "blur");
375    
376            for (int second = 0;; second++) {
377                if (second >= waitSeconds) {
378                    SeleneseTestBase.fail("timeout");
379                }
380                try {
381                    if (getAttributeByName("field26", "class").matches(REGEX_ERROR)) {
382                        break;
383                    }
384                } catch (Exception e) {}
385                Thread.sleep(1000);
386            }
387    
388            assertAttributeClassRegexMatches("field26", REGEX_ERROR);
389    
390            checkByXpath("//*[@name='field24' and @value='case4']");
391            clearTextByName("field27");
392            waitAndTypeByName("field27", "A");
393            fireEvent("field27", "blur");
394            clearTextByName("field28");
395            waitAndTypeByName("field28", "");
396            fireEvent("field28", "blur");
397    
398            for (int second = 0;; second++) {
399                if (second >= waitSeconds) {
400                    SeleneseTestBase.fail("timeout");
401                }
402                try {
403                    if (getAttributeByName("field28", "class").matches(REGEX_ERROR)) {
404                        break;
405                    }
406                } catch (Exception e) {}
407                Thread.sleep(1000);
408            }
409    
410            assertAttributeClassRegexMatches("field28", REGEX_ERROR);
411    
412            checkByXpath("//*[@name='field24' and @value='case3']");
413            fireEvent("field24", "blur");
414    
415            for (int second = 0;; second++) {
416                if (second >= waitSeconds) {
417                    SeleneseTestBase.fail("timeout");
418                }
419                try {
420                    if (getAttributeByName("field28", "class").matches(REGEX_VALID)) {
421                        break;
422                    }
423                } catch (Exception e) {}
424                Thread.sleep(1000);
425            }
426    
427            assertAttributeClassRegexMatches("field28", REGEX_VALID);
428    
429            clearTextByName("field28");
430            waitAndTypeByName("field28", "B");
431            fireEvent("field28", "blur");
432            checkByXpath("//*[@name='field24' and @value='case4']");
433            fireEvent("field24", "blur");
434    
435            for (int second = 0;; second++) {
436                if (second >= waitSeconds) {
437                    SeleneseTestBase.fail("timeout");
438                }
439                try {
440                    if (getAttributeByName("field28", "class").matches(REGEX_VALID)) {
441                        break;
442                    }
443                } catch (Exception e) {}
444                Thread.sleep(1000);
445            }
446    
447            assertAttributeClassRegexMatches("field28", REGEX_VALID);
448    
449            clearTextByName("field31");
450            waitAndTypeByName("field31", "B");
451            clearTextByName("field32");
452            waitAndTypeByName("field32", "B");
453            waitAndTypeByName("field33", "");
454            fireEvent("field33", "blur");
455            assertAttributeClassRegexMatches("field33", REGEX_ERROR);
456    
457            clearTextByName("field33");
458            waitAndTypeByName("field33", "B");
459            fireEvent("field33", "blur");
460            assertAttributeClassRegexMatches("field33", REGEX_VALID);
461    
462            clearTextByName("field32");
463            waitAndTypeByName("field32", "A");
464            clearTextByName("field33");
465            waitAndTypeByName("field33", "");
466            fireEvent("field33", "blur");
467            assertAttributeClassRegexMatches("field33", REGEX_VALID);
468        }
469    }