001    /**
002     * Copyright 2005-2014 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    package edu.sampleu.krad.compview;
017    
018    import com.thoughtworks.selenium.SeleneseTestBase;
019    import org.junit.Test;
020    import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
021    
022    /**
023     * @author Kuali Rice Team (rice.collab@kuali.org)
024     */
025    public class ConstraintsAft extends WebDriverLegacyITBase {
026    
027        /**
028         * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3
029         */
030        public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3";
031    
032        @Override
033        protected String getBookmarkUrl() {
034            return BOOKMARK_URL;
035        }
036    
037        @Override
038        protected void navigate() throws Exception {
039            waitAndClickKRAD();
040            waitAndClickByXpath(KITCHEN_SINK_XPATH);
041            switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
042            waitAndClickByXpath("//ul[@class='nav nav-list']/li[5]/a");
043            waitAndClickByXpath("//a[@id='UifCompView-Navigation3']");
044        }
045    
046        protected void testConstraints() throws Exception {
047            checkForIncidentReport("testConstraints");
048    
049            // TODO break out into smaller methods, especially if a test flaps. https://jira.kuali.org/browse/KULRICE-9711
050            fireEvent("field10", "focus");
051            waitAndTypeByName("field10", "2");
052            fireEvent("field10", "blur");
053            assertAttributeClassRegexMatches("field10", REGEX_ERROR);
054    
055            fireEvent("field10", "focus");
056            clearTextByName("field10");
057            waitAndTypeByName("field10", "51");
058            fireEvent("field10", "blur");
059            assertAttributeClassRegexMatches("field10", REGEX_ERROR);
060    
061            fireEvent("field10", "focus");
062            clearTextByName("field10");
063            waitAndTypeByName("field10", "25");
064            fireEvent("field10", "blur");
065            assertAttributeClassRegexMatches("field10", REGEX_VALID);
066    
067            waitAndTypeByName("field14", "A");
068            fireEvent("field14", "blur");
069    
070            assertAttributeClassRegexMatches("field14", REGEX_ERROR);
071            clearTextByName("field11");
072            waitAndTypeByName("field11", "A");
073            fireEvent("field11", "blur");
074            assertAttributeClassRegexMatches("field11", REGEX_VALID);
075            assertAttributeClassRegexMatches("field14", REGEX_VALID);
076    
077            clearTextByName("field11");
078            waitAndTypeByName("field11", "");
079            fireEvent("field11", "blur");
080            assertAttributeClassRegexMatches("field14", REGEX_ERROR);
081    
082            clearTextByName("field12");
083            waitAndTypeByName("field12", "A");
084            fireEvent("field12", "blur");
085            assertAttributeClassRegexMatches("field14", REGEX_ERROR);
086    
087            clearTextByName("field13");
088            waitAndTypeByName("field13", "A");
089            fireEvent("field13", "blur");
090            assertAttributeClassRegexMatches("field13", REGEX_VALID);
091            assertAttributeClassRegexMatches("field14", REGEX_VALID);
092    
093            clearTextByName("field11");
094            waitAndTypeByName("field11", "A");
095            fireEvent("field11", "blur");
096            assertAttributeClassRegexMatches("field11", REGEX_VALID);
097            assertAttributeClassRegexMatches("field14", REGEX_VALID);
098    
099            waitAndTypeByName("field18", "A");
100            fireEvent("field18", "blur");
101            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
102    
103            waitAndTypeByName("field15", "A");
104            fireEvent("field15", "blur");
105            assertAttributeClassRegexMatches("field15", REGEX_VALID);
106            assertAttributeClassRegexMatches("field18", REGEX_VALID);
107    
108            clearTextByName("field15");
109            waitAndTypeByName("field15", "");
110            fireEvent("field15", "blur");
111            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
112    
113            clearTextByName("field16");
114            waitAndTypeByName("field16", "A");
115            fireEvent("field16", "blur");
116            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
117    
118            clearTextByName("field17");
119            waitAndTypeByName("field17", "A");
120            fireEvent("field17", "blur");
121            assertAttributeClassRegexMatches("field17", REGEX_VALID);
122            assertAttributeClassRegexMatches("field18", REGEX_VALID);
123    
124            clearTextByName("field15");
125            waitAndTypeByName("field15", "A");
126            fireEvent("field15", "blur");
127            assertAttributeClassRegexMatches("field18", REGEX_ERROR);
128    
129            waitAndTypeByName("field23", "A");
130            fireEvent("field23", "blur");
131            assertAttributeClassRegexMatches("field23", REGEX_ERROR);
132    
133            clearTextByName("field19");
134            waitAndTypeByName("field19", "A");
135            fireEvent("field19", "blur");
136            assertAttributeClassRegexMatches("field23", REGEX_VALID);
137    
138            clearTextByName("field19");
139            waitAndTypeByName("field19", "");
140            fireEvent("field19", "blur");
141            waitAndTypeByName("field20", "B");
142            fireEvent("field20", "blur");
143            assertAttributeClassRegexMatches("field23", REGEX_VALID);
144    
145            clearTextByName("field20");
146            waitAndTypeByName("field20", "");
147            fireEvent("field20", "blur");
148            assertAttributeClassRegexMatches("field23", REGEX_ERROR);
149    
150            clearTextByName("field21");
151            waitAndTypeByName("field21", "C");
152            fireEvent("field21", "blur");
153            assertAttributeClassRegexMatches("field23", REGEX_ERROR);
154    
155            clearTextByName("field22");
156            waitAndTypeByName("field22", "D");
157            fireEvent("field22", "blur");
158            assertAttributeClassRegexMatches("field23", REGEX_VALID);
159    
160            clearTextByName("field19");
161            waitAndTypeByName("field19", "D");
162            fireEvent("field19", "blur");
163            assertAttributeClassRegexMatches("field23", REGEX_VALID);
164    
165            clearTextByName("field20");
166            waitAndTypeByName("field20", "D");
167            fireEvent("field20", "blur");
168            assertAttributeClassRegexMatches("field23", REGEX_VALID);
169    
170            checkByXpath("//*[@name='field24' and @value='case1']");
171            clearTextByName("field25");
172            waitAndTypeByName("field25", "");
173            fireEvent("field25", "blur");
174            assertAttributeClassRegexMatches("field25", REGEX_ERROR);
175    
176            checkByXpath("//*[@name='field24' and @value='case4']");
177            fireEvent("field24", "blur");
178    
179            for (int second = 0;; second++) {
180                if (second >= waitSeconds) {
181                    SeleneseTestBase.fail("timeout");
182                }
183                try {
184                    if (waitAndGetAttributeByName("field25", "class").matches(REGEX_VALID)) {
185                        break;
186                    }
187                } catch (Exception e) {}
188                Thread.sleep(1000);
189            }
190    
191            assertAttributeClassRegexMatches("field25", REGEX_VALID);
192    
193            checkByXpath("//*[@name='field24' and @value='case1']");
194            fireEvent("field24", "blur");
195            clearTextByName("field25");
196            waitAndTypeByName("field25", "$100");
197            fireEvent("field25", "blur");
198    
199            for (int second = 0;; second++) {
200                if (second >= waitSeconds) {
201                    SeleneseTestBase.fail("timeout");
202                }
203                try {
204                    if (waitAndGetAttributeByName("field25", "class").matches(REGEX_VALID)) {
205                        break;
206                    }
207                } catch (Exception e) {}
208                Thread.sleep(1000);
209            }
210    
211            assertAttributeClassRegexMatches("field25", REGEX_VALID);
212    
213            checkByXpath("//*[@name='field24' and @value='case2']");
214            fireEvent("field24", "blur");
215    
216            for (int second = 0;; second++) {
217                if (second >= waitSeconds) {
218                    SeleneseTestBase.fail("timeout");
219                }
220                try {
221                    if (waitAndGetAttributeByName("field25", "class").matches(REGEX_ERROR)) {
222                        break;
223                    }
224                } catch (Exception e) {}
225                Thread.sleep(1000);
226            }
227    
228            assertAttributeClassRegexMatches("field25", REGEX_ERROR);
229    
230            clearTextByName("field25");
231            waitAndTypeByName("field25", "A100");
232            fireEvent("field25", "blur");
233            assertAttributeClassRegexMatches("field25", REGEX_VALID);
234    
235            checkByXpath("//*[@name='field24' and @value='case3']");
236            fireEvent("field24", "blur");
237            clearTextByName("field26");
238            waitAndTypeByName("field26", "6000");
239            fireEvent("field26", "blur");
240    
241            for (int second = 0;; second++) {
242                if (second >= waitSeconds) {
243                    SeleneseTestBase.fail("timeout");
244                }
245                try {
246                    if (waitAndGetAttributeByName("field26", "class").matches(REGEX_ERROR)) {
247                        break;
248                    }
249                } catch (Exception e) {}
250                Thread.sleep(1000);
251            }
252    
253            assertAttributeClassRegexMatches("field26", REGEX_ERROR);
254    
255            clearTextByName("field26");
256            waitAndTypeByName("field26", "501");
257            fireEvent("field26", "blur");
258            assertAttributeClassRegexMatches("field26", REGEX_ERROR);
259    
260            clearTextByName("field26");
261            waitAndTypeByName("field26", "499");
262            fireEvent("field26", "blur");
263            assertAttributeClassRegexMatches("field26", REGEX_VALID);
264    
265            clearTextByName("field26");
266            waitAndTypeByName("field26", "6000");
267            fireEvent("field26", "blur");
268            checkByXpath("//*[@name='field24' and @value='case3']");
269            fireEvent("field24", "blur");
270    
271            for (int second = 0;; second++) {
272                if (second >= waitSeconds) {
273                    SeleneseTestBase.fail("timeout");
274                }
275                try {
276                    if (waitAndGetAttributeByName("field26", "class").matches(REGEX_ERROR)) {
277                        break;
278                    }
279                } catch (Exception e) {}
280                Thread.sleep(1000);
281            }
282    
283            assertAttributeClassRegexMatches("field26", REGEX_ERROR);
284    
285            checkByXpath("//*[@name='field24' and @value='case4']");
286            clearTextByName("field27");
287            waitAndTypeByName("field27", "A");
288            fireEvent("field27", "blur");
289            clearTextByName("field28");
290            waitAndTypeByName("field28", "");
291            fireEvent("field28", "blur");
292    
293            for (int second = 0;; second++) {
294                if (second >= waitSeconds) {
295                    SeleneseTestBase.fail("timeout");
296                }
297                try {
298                    if (waitAndGetAttributeByName("field28", "class").matches(REGEX_ERROR)) {
299                        break;
300                    }
301                } catch (Exception e) {}
302                Thread.sleep(1000);
303            }
304    
305            assertAttributeClassRegexMatches("field28", REGEX_ERROR);
306    
307            checkByXpath("//*[@name='field24' and @value='case3']");
308            fireEvent("field24", "blur");
309    
310            for (int second = 0;; second++) {
311                if (second >= waitSeconds) {
312                    SeleneseTestBase.fail("timeout");
313                }
314                try {
315                    if (waitAndGetAttributeByName("field28", "class").matches(REGEX_VALID)) {
316                        break;
317                    }
318                } catch (Exception e) {}
319                Thread.sleep(1000);
320            }
321    
322            assertAttributeClassRegexMatches("field28", REGEX_VALID);
323    
324            clearTextByName("field28");
325            waitAndTypeByName("field28", "B");
326            fireEvent("field28", "blur");
327            checkByXpath("//*[@name='field24' and @value='case4']");
328            fireEvent("field24", "blur");
329    
330            for (int second = 0;; second++) {
331                if (second >= waitSeconds) {
332                    SeleneseTestBase.fail("timeout");
333                }
334                try {
335                    if (waitAndGetAttributeByName("field28", "class").matches(REGEX_VALID)) {
336                        break;
337                    }
338                } catch (Exception e) {}
339                Thread.sleep(1000);
340            }
341    
342            assertAttributeClassRegexMatches("field28", REGEX_VALID);
343    
344            clearTextByName("field31");
345            waitAndTypeByName("field31", "B");
346            clearTextByName("field32");
347            waitAndTypeByName("field32", "B");
348            waitAndTypeByName("field33", "");
349            fireEvent("field33", "blur");
350            assertAttributeClassRegexMatches("field33", REGEX_ERROR);
351    
352            clearTextByName("field33");
353            waitAndTypeByName("field33", "B");
354            fireEvent("field33", "blur");
355            assertAttributeClassRegexMatches("field33", REGEX_VALID);
356    
357            clearTextByName("field32");
358            waitAndTypeByName("field32", "A");
359            clearTextByName("field33");
360            waitAndTypeByName("field33", "");
361            fireEvent("field33", "blur");
362            assertAttributeClassRegexMatches("field33", REGEX_VALID);
363        }
364    
365        @Test
366        public void testConstraintsBookmark() throws Exception {
367            testConstraints();
368            passed();
369        }
370    
371        @Test
372        public void testConstraintsNav() throws Exception {
373            testConstraints();
374            passed();
375        }
376    }