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