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            SeleneseTestBase.assertEquals("true", getAttributeByName("field1", "aria-invalid"));
074            assertAttributeClassRegexMatches("field1", REGEX_ERROR);
075            SeleneseTestBase.assertTrue(isTextPresent("Required"));
076    
077            fireMouseOverEventByName("field1");
078    
079            for (int second = 0;; second++) {
080                if (second >= 10) {
081                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
082                }
083    
084                try {
085                    if (isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
086                        break;
087                    }
088                } catch (Exception e) {}
089    
090                Thread.sleep(1000);
091            }
092    
093            SeleneseTestBase.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems  .uif-errorMessageItem-field"));
094    
095            waitAndTypeByName("field1", "a");
096            fireEvent("field1", "blur");
097            fireMouseOverEventByName("field1");
098    
099            for (int second = 0;; second++) {
100                if (second >= 10) {
101                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
102                }
103    
104                try {
105                    if (!isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
106                        break;
107                    }
108                } catch (Exception e) {}
109    
110                Thread.sleep(1000);
111            }
112    
113            SeleneseTestBase.assertFalse(isVisibleByXpath(
114                    "//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']"));
115    
116            fireEvent("field1", "blur");
117            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field1' and @aria-invalid]"));
118            assertAttributeClassRegexMatches("field1", REGEX_VALID);
119            SeleneseTestBase.assertTrue(isTextPresent("Required"));
120    
121            fireEvent("field2", "focus");
122            fireEvent("field2", "blur");
123            fireMouseOverEventByName("field2");
124            SeleneseTestBase.assertEquals("true", getAttributeByName("field2", "aria-invalid"));
125            assertAttributeClassRegexMatches("field2", REGEX_ERROR);
126            SeleneseTestBase.assertTrue(isTextPresent("Required"));
127    
128            fireEvent("field2", "focus");
129            waitAndTypeByName("field2", "a");
130            fireEvent("field2", "blur");
131            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
132            assertAttributeClassRegexMatches("field2", REGEX_VALID);
133            SeleneseTestBase.assertFalse(isElementPresentByXpath("//textarea[@name='field2']/../img[@alt='Error']"));
134    
135            fireEvent("field3", "focus");
136            fireEvent("field3", "blur");
137            fireMouseOverEventByName("field3");
138            SeleneseTestBase.assertEquals("true", getAttributeByName("field3", "aria-invalid"));
139            assertAttributeClassRegexMatches("field3", REGEX_ERROR);
140            SeleneseTestBase.assertTrue(isTextPresent("Required"));
141    
142            fireEvent("field3", "focus");
143            selectByName("field3", "Option 1");
144            fireEvent("field3", "blur");
145            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]"));
146            assertAttributeClassRegexMatches("field3", REGEX_VALID);
147            SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']"));
148    
149            fireEvent("field114", "focus");
150            fireMouseOverEventByName("field114");
151            driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click();
152            fireEvent("field114", "blur");
153            SeleneseTestBase.assertEquals("true", getAttributeByName("field114", "aria-invalid"));
154            assertAttributeClassRegexMatches("field114", REGEX_ERROR);
155            SeleneseTestBase.assertTrue(isTextPresent("Required"));
156    
157            fireEvent("field114", "focus");
158            selectByName("field114", "Option 1");
159            fireEvent("field114", "blur");
160            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field114' and @aria-invalid]"));
161            assertAttributeClassRegexMatches("field114", REGEX_VALID);
162            SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field114']/../img[@alt='Error']"));
163    
164            fireEvent("field117", "3", "focus");
165            uncheckByXpath("//*[@name='field117' and @value='3']");
166            fireEvent("field117", "blur");
167            fireMouseOverEventByName("field117");
168    
169            for (int second = 0;; second++) {
170                if (second >= 10) {
171                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
172                }
173    
174                try {
175                    if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
176                        break;
177                    }
178                } catch (Exception e) {}
179    
180                Thread.sleep(1000);
181            }
182    
183            SeleneseTestBase.assertEquals("true", getAttributeByXpath("//*[@name='field117' and @value='1']",
184                    "aria-invalid"));
185            SeleneseTestBase.assertTrue(getAttributeByXpath("//*[@name='field117' and @value='1']", "class").matches(
186                    REGEX_ERROR));
187            SeleneseTestBase.assertTrue(isTextPresent("Required"));
188    
189            fireEvent("field117", "3", "focus");
190            checkByXpath("//*[@name='field117' and @value='3']");
191            fireEvent("field117", "3", "blur");
192    
193            for (int second = 0;; second++) {
194                if (second >= waitSeconds) {
195                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
196                }
197    
198                try {
199                    if (!isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) {
200                        break;
201                    }
202                } catch (Exception e) {}
203    
204                Thread.sleep(1000);
205            }
206    
207            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field117' and @value='3' and @aria-invalid]"));
208            SeleneseTestBase.assertTrue(getAttributeByXpath("//*[@name='field117' and @value='3']", "class").matches(REGEX_VALID));
209            SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']"));
210    
211            fireEvent("bField1", "focus");
212            uncheckByName("bField1");
213            fireEvent("bField1", "blur");
214            fireMouseOverEventByName("bField1");
215            SeleneseTestBase.assertEquals("true", getAttributeByName("bField1", "aria-invalid"));
216            assertAttributeClassRegexMatches("bField1", REGEX_ERROR);
217            SeleneseTestBase.assertTrue(isTextPresent("Required"));
218    
219            fireEvent("bField1", "focus");
220            checkByName("bField1");
221            fireEvent("bField1", "blur");
222            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='bField1' and @aria-invalid]"));
223            assertAttributeClassRegexMatches("bField1", REGEX_VALID);
224            SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
225    
226            fireEvent("field115", "3", "focus");
227            uncheckByXpath("//*[@name='field115' and @value='3']");
228            uncheckByXpath("//*[@name='field115' and @value='4']");
229            fireEvent("field115", "blur");
230            fireMouseOverEventByName("field115");
231    
232            for (int second = 0;; second++) {
233                if (second >= waitSeconds) {
234                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
235                }
236    
237                try {
238                    if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
239                        break;
240                    }
241                } catch (Exception e) {}
242    
243                Thread.sleep(1000);
244            }
245    
246            SeleneseTestBase.assertEquals("true", getAttributeByXpath("//*[@name='field115' and @value='1']", "aria-invalid"));
247            SeleneseTestBase.assertTrue(getAttributeByXpath("//*[@name='field115' and @value='1']", "class").matches(REGEX_ERROR));
248            SeleneseTestBase.assertTrue(isTextPresent("Required"));
249    
250            fireEvent("field115", "3", "focus");
251            checkByXpath("//*[@name='field115' and @value='3']");
252            checkByXpath("//*[@name='field115' and @value='4']");
253            fireEvent("field115", "blur");
254    
255            for (int second = 0;; second++) {
256                if (second >= waitSeconds) {
257                    SeleneseTestBase.fail(TIMEOUT_MESSAGE);
258                }
259    
260                try {
261                    if (!isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) {
262                        break;
263                    }
264                } catch (Exception e) {}
265    
266                Thread.sleep(1000);
267            }
268    
269            SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field115' and @value='3' and @aria-invalid]"));
270            SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']"));
271        }
272    }