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    package edu.samplu.krad.validationmessagesview;
017    
018    import com.thoughtworks.selenium.SeleneseTestBase;
019    import edu.samplu.common.Failable;
020    import edu.samplu.common.ITUtil;
021    import edu.samplu.common.WebDriverLegacyITBase;
022    import org.openqa.selenium.By;
023    
024    /**
025     * Tests the Component section in Rice.
026     *
027     * @author Kuali Rice Team (rice.collab@kuali.org)
028     */
029    public abstract class ClientErrorsAbstractSmokeTestBase extends WebDriverLegacyITBase {
030    
031        /**
032         * "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"
033         */
034        public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start";
035    
036        protected void bookmark() {
037            open(ITUtil.getBaseUrlString() + BOOKMARK_URL);
038        }
039    
040        /**
041         * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}.
042         * Bookmark Tests should override and return {@link edu.samplu.krad.validationmessagesview.ClientErrorsAbstractSmokeTestBase#BOOKMARK_URL}
043         * {@inheritDoc}
044         * @return
045         */
046        @Override
047        public String getTestUrl() {
048            return ITUtil.PORTAL;
049        }
050    
051        protected void navigation() throws InterruptedException {
052            waitAndClickKRAD();
053            waitAndClickByXpath(VALIDATION_FRAMEWORK_DEMO_XPATH);
054            switchToWindow(KUALI_VIEW_WINDOW_TITLE);
055        }
056    
057        protected void testClientErrorsNav(Failable failable) throws Exception {
058            navigation();
059            testClientErrors();
060            passed();
061        }
062    
063        protected void testClientErrorsBookmark(Failable failable) throws Exception {
064            testClientErrors();
065            passed();
066        }
067    
068        protected void testClientErrors() throws Exception {
069            fireEvent("field1", "focus");
070            fireEvent("field1", "blur");
071            Thread.sleep(3000);
072            fireMouseOverEventByName("field1");
073            Thread.sleep(500);
074            SeleneseTestBase.assertEquals("true", getAttributeByName("field1", "aria-invalid"));
075            assertAttributeClassRegexMatches("field1", REGEX_ERROR);
076            SeleneseTestBase.assertTrue(isTextPresent("Required"));
077    
078            fireMouseOverEventByName("field1");
079    
080            for (int second = 0;; second++) {
081                if (second >= 10) {
082                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
083                }
084    
085                try {
086                    if (isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
087                        break;
088                    }
089                } catch (Exception e) {}
090    
091                Thread.sleep(1000);
092            }
093    
094            SeleneseTestBase.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems  .uif-errorMessageItem-field"));
095    
096            waitAndTypeByName("field1", "a");
097            fireEvent("field1", "blur");
098            fireMouseOverEventByName("field1");
099    
100            for (int second = 0;; second++) {
101                if (second >= 10) {
102                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
103                }
104    
105                try {
106                    if (!isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
107                        break;
108                    }
109                } catch (Exception e) {}
110    
111                Thread.sleep(1000);
112            }
113    
114            SeleneseTestBase.assertFalse(isVisibleByXpath(
115                    "//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']"));
116    
117            fireEvent("field1", "blur");
118            Thread.sleep(500);
119            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field1' and @aria-invalid]"));
120            assertAttributeClassRegexMatches("field1", REGEX_VALID);
121            SeleneseTestBase.assertTrue(isTextPresent("Required"));
122    
123            fireEvent("field2", "focus");
124            fireEvent("field2", "blur");
125            fireMouseOverEventByName("field2");
126            Thread.sleep(500);
127            //        SeleneseTestBase.assertEquals("true", getAttributeByName("field2", "aria-invalid"));
128            SeleneseTestBase.assertEquals("true", getAttributeByName("field2", "aria-required"));
129            assertAttributeClassRegexMatches("field2", REGEX_ERROR);
130            SeleneseTestBase.assertTrue(isTextPresent("Required"));
131    
132            fireEvent("field2", "focus");
133            waitAndTypeByName("field2", "a");
134            fireEvent("field2", "blur");
135            Thread.sleep(500);
136            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
137            assertAttributeClassRegexMatches("field2", REGEX_VALID);
138            SeleneseTestBase.assertFalse(isElementPresentByXpath("//textarea[@name='field2']/../img[@alt='Error']"));
139    
140            fireEvent("field3", "focus");
141            fireEvent("field3", "blur");
142            fireMouseOverEventByName("field3");
143            Thread.sleep(500);
144            SeleneseTestBase.assertEquals("true", getAttributeByName("field3", "aria-invalid"));
145            assertAttributeClassRegexMatches("field3", REGEX_ERROR);
146            SeleneseTestBase.assertTrue(isTextPresent("Required"));
147    
148            fireEvent("field3", "focus");
149            selectByName("field3", "Option 1");
150            fireEvent("field3", "blur");
151            Thread.sleep(500);
152            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]"));
153            assertAttributeClassRegexMatches("field3", REGEX_VALID);
154            SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']"));
155    
156            fireEvent("field114", "focus");
157            fireMouseOverEventByName("field114");
158            driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click();
159            fireEvent("field114", "blur");
160            Thread.sleep(500);
161            SeleneseTestBase.assertEquals("true", getAttributeByName("field114", "aria-invalid"));
162            assertAttributeClassRegexMatches("field114", REGEX_ERROR);
163            SeleneseTestBase.assertTrue(isTextPresent("Required"));
164    
165            fireEvent("field114", "focus");
166            selectByName("field114", "Option 1");
167            fireEvent("field114", "blur");
168            Thread.sleep(500);
169            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field114' and @aria-invalid]"));
170            assertAttributeClassRegexMatches("field114", REGEX_VALID);
171            SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field114']/../img[@alt='Error']"));
172    
173            fireEvent("field117", "3", "focus");
174            uncheckByXpath("//*[@name='field117' and @value='3']");
175            fireEvent("field117", "blur");
176            fireMouseOverEventByName("field117");
177    
178            for (int second = 0;; second++) {
179                if (second >= 10) {
180                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
181                }
182    
183                try {
184                    if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
185                        break;
186                    }
187                } catch (Exception e) {}
188    
189                Thread.sleep(1000);
190            }
191    
192            SeleneseTestBase.assertEquals("true", getAttributeByXpath("//*[@name='field117' and @value='1']",
193                    "aria-invalid"));
194            SeleneseTestBase.assertTrue(getAttributeByXpath("//*[@name='field117' and @value='1']", "class").matches(
195                    REGEX_ERROR));
196            SeleneseTestBase.assertTrue(isTextPresent("Required"));
197    
198            fireEvent("field117", "3", "focus");
199            checkByXpath("//*[@name='field117' and @value='3']");
200            fireEvent("field117", "3", "blur");
201    
202            for (int second = 0;; second++) {
203                if (second >= waitSeconds) {
204                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
205                }
206    
207                try {
208                    if (!isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) {
209                        break;
210                    }
211                } catch (Exception e) {}
212    
213                Thread.sleep(1000);
214            }
215    
216            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field117' and @value='3' and @aria-invalid]"));
217            SeleneseTestBase.assertTrue(getAttributeByXpath("//*[@name='field117' and @value='3']", "class").matches(REGEX_VALID));
218            SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']"));
219    
220            fireEvent("bField1", "focus");
221            uncheckByName("bField1");
222            fireEvent("bField1", "blur");
223            fireMouseOverEventByName("bField1");
224            Thread.sleep(500);
225            SeleneseTestBase.assertEquals("true", getAttributeByName("bField1", "aria-invalid"));
226            assertAttributeClassRegexMatches("bField1", REGEX_ERROR);
227            SeleneseTestBase.assertTrue(isTextPresent("Required"));
228    
229            fireEvent("bField1", "focus");
230            checkByName("bField1");
231            fireEvent("bField1", "blur");
232            Thread.sleep(500);
233            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='bField1' and @aria-invalid]"));
234            assertAttributeClassRegexMatches("bField1", REGEX_VALID);
235            SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
236    
237            fireEvent("field115", "3", "focus");
238            uncheckByXpath("//*[@name='field115' and @value='3']");
239            uncheckByXpath("//*[@name='field115' and @value='4']");
240            fireEvent("field115", "blur");
241            fireMouseOverEventByName("field115");
242    
243            for (int second = 0;; second++) {
244                if (second >= waitSeconds) {
245                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
246                }
247    
248                try {
249                    if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
250                        break;
251                    }
252                } catch (Exception e) {}
253    
254                Thread.sleep(1000);
255            }
256    
257            SeleneseTestBase.assertEquals("true", getAttributeByXpath("//*[@name='field115' and @value='1']", "aria-invalid"));
258            SeleneseTestBase.assertTrue(getAttributeByXpath("//*[@name='field115' and @value='1']", "class").matches(REGEX_ERROR));
259            SeleneseTestBase.assertTrue(isTextPresent("Required"));
260    
261            fireEvent("field115", "3", "focus");
262            checkByXpath("//*[@name='field115' and @value='3']");
263            checkByXpath("//*[@name='field115' and @value='4']");
264            fireEvent("field115", "blur");
265    
266            for (int second = 0;; second++) {
267                if (second >= waitSeconds) {
268                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
269                }
270    
271                try {
272                    if (!isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) {
273                        break;
274                    }
275                } catch (Exception e) {}
276    
277                Thread.sleep(1000);
278            }
279    
280            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field115' and @value='3' and @aria-invalid]"));
281            SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']"));
282        }
283    }