View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.krad.validationmessagesview;
17  
18  import com.thoughtworks.selenium.SeleneseTestBase;
19  import org.kuali.rice.testtools.common.JiraAwareFailable;
20  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
21  import org.openqa.selenium.By;
22  
23  /**
24   * Tests the Component section in Rice.
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public abstract class ClientErrorsAftBase extends WebDriverLegacyITBase {
29  
30      /**
31       * "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start";
34  
35      @Override
36      public String getBookmarkUrl() {
37          return BOOKMARK_URL;
38      }
39  
40  
41      protected void navigation() throws InterruptedException {
42          waitAndClickKRAD();
43          waitAndClickByXpath(VALIDATION_FRAMEWORK_DEMO_XPATH);
44          switchToWindow(KUALI_VIEW_WINDOW_TITLE);
45      }
46  
47      protected void testClientErrorsNav(JiraAwareFailable failable) throws Exception {
48          navigation();
49          testClientErrors();
50          passed();
51      }
52  
53      protected void testClientErrorsBookmark(JiraAwareFailable failable) throws Exception {
54          testClientErrors();
55          passed();
56      }
57  
58      protected void testClientErrors() throws Exception {
59          fireEvent("field1", "focus");
60          fireEvent("field1", "blur");
61          Thread.sleep(3000);
62          fireMouseOverEventByName("field1");
63          waitIsVisibleByXpath("//div[@class='popover top in uif-tooltip-error-cs']");
64  
65          waitAndTypeByName("field1", "a");
66          fireEvent("field1", "blur");
67          fireMouseOverEventByName("field1");
68          assertFalse(isVisibleByXpath(
69                  "//div[@class='popover top in uif-tooltip-error-cs']"));
70  
71          fireEvent("field2", "focus");
72          fireEvent("field2", "blur");
73          fireMouseOverEventByName("field2");
74          Thread.sleep(500);
75          //        SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-invalid"));
76          SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-required"));
77  
78          fireEvent("field2", "focus");
79          waitAndTypeByName("field2", "a");
80          fireEvent("field2", "blur");
81          Thread.sleep(500);
82          assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
83  
84          fireEvent("field3", "focus");
85          fireEvent("field3", "blur");
86          fireMouseOverEventByName("field3");
87  
88          fireEvent("field3", "focus");
89          selectByName("field3", "Option 1");
90          fireEvent("field3", "blur");
91          Thread.sleep(500);
92          assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]"));
93  
94          fireEvent("field114", "focus");
95          fireMouseOverEventByName("field114");
96          driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click();
97          fireEvent("field114", "blur");
98          Thread.sleep(500);
99          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 }