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