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        waitIsVisibleByXpath("//div[@class='popover top in uif-tooltip-error-cs']");
064
065        waitAndTypeByName("field1", "a");
066        fireEvent("field1", "blur");
067        fireMouseOverEventByName("field1");
068        assertFalse(isVisibleByXpath(
069                "//div[@class='popover top in uif-tooltip-error-cs']"));
070
071        fireEvent("field2", "focus");
072        fireEvent("field2", "blur");
073        fireMouseOverEventByName("field2");
074        Thread.sleep(500);
075        //        SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-invalid"));
076        SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-required"));
077
078        fireEvent("field2", "focus");
079        waitAndTypeByName("field2", "a");
080        fireEvent("field2", "blur");
081        Thread.sleep(500);
082        assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
083
084        fireEvent("field3", "focus");
085        fireEvent("field3", "blur");
086        fireMouseOverEventByName("field3");
087
088        fireEvent("field3", "focus");
089        selectByName("field3", "Option 1");
090        fireEvent("field3", "blur");
091        Thread.sleep(500);
092        assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]"));
093
094        fireEvent("field114", "focus");
095        fireMouseOverEventByName("field114");
096        driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click();
097        fireEvent("field114", "blur");
098        Thread.sleep(500);
099        SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field114", "aria-invalid"));
100
101        fireEvent("field114", "focus");
102        selectByName("field114", "Option 1");
103        fireEvent("field114", "blur");
104        Thread.sleep(500);
105        assertFalse(isElementPresentByXpath("//*[@name='field114' and @aria-invalid]"));
106
107        fireEvent("field117", "3", "focus");
108        checkByXpath("//*[@name='field117' and @value='3']");
109        fireEvent("field117", "3", "blur");
110
111        for (int second = 0;; second++) {
112            if (second >= waitSeconds) {
113                SeleneseTestBase.fail(TIMEOUT_MESSAGE);
114            }
115
116            try {
117                if (!isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) {
118                    break;
119                }
120            } catch (Exception e) {}
121
122            Thread.sleep(1000);
123        }
124
125        assertFalse(isElementPresentByXpath("//*[@name='field117' and @value='3' and @aria-invalid]"));
126        assertTrue(waitAndGetAttributeByXpath("//*[@name='field117' and @value='3']", "class").matches(REGEX_VALID));
127        assertFalse(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']"));
128
129        fireEvent("bField1", "focus");
130        uncheckByName("bField1");
131        fireEvent("bField1", "blur");
132        fireMouseOverEventByName("bField1");
133        Thread.sleep(500);
134        SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("bField1", "aria-invalid"));
135        assertAttributeClassRegexMatches("bField1", REGEX_ERROR);
136        assertTrue(isTextPresent("Required"));
137
138        fireEvent("bField1", "focus");
139        checkByName("bField1");
140        fireEvent("bField1", "blur");
141        Thread.sleep(500);
142        assertFalse(isElementPresentByXpath("//*[@name='bField1' and @aria-invalid]"));
143        assertAttributeClassRegexMatches("bField1", REGEX_VALID);
144        assertFalse(isElementPresentByXpath("//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
145
146        fireEvent("field115", "3", "focus");
147        uncheckByXpath("//*[@name='field115' and @value='3']");
148        uncheckByXpath("//*[@name='field115' and @value='4']");
149        fireEvent("field115", "blur");
150        fireMouseOverEventByName("field115");
151
152        fireEvent("field115", "3", "focus");
153        checkByXpath("//*[@name='field115' and @value='3']");
154        checkByXpath("//*[@name='field115' and @value='4']");
155        fireEvent("field115", "blur");
156
157        for (int second = 0;; second++) {
158            if (second >= waitSeconds) {
159                SeleneseTestBase.fail(TIMEOUT_MESSAGE);
160            }
161
162            try {
163                if (!isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) {
164                    break;
165                }
166            } catch (Exception e) {}
167
168            Thread.sleep(1000);
169        }
170
171        assertFalse(isElementPresentByXpath("//*[@name='field115' and @value='3' and @aria-invalid]"));
172        assertFalse(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']"));
173    }
174}