View Javadoc

1   /**
2    * Copyright 2005-2013 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.samplu.krad.validationmessagesview;
17  
18  import com.thoughtworks.selenium.SeleneseTestBase;
19  import edu.samplu.common.Failable;
20  import edu.samplu.common.ITUtil;
21  import edu.samplu.common.WebDriverLegacyITBase;
22  import org.openqa.selenium.By;
23  
24  /**
25   * Tests the Component section in Rice.
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public abstract class ClientErrorsAbstractSmokeTestBase extends WebDriverLegacyITBase {
30  
31      /**
32       * "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"
33       */
34      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start";
35  
36      protected void bookmark() {
37          open(ITUtil.getBaseUrlString() + BOOKMARK_URL);
38      }
39  
40      /**
41       * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}.
42       * Bookmark Tests should override and return {@link edu.samplu.krad.validationmessagesview.ClientErrorsAbstractSmokeTestBase#BOOKMARK_URL}
43       * {@inheritDoc}
44       * @return
45       */
46      @Override
47      public String getTestUrl() {
48          return ITUtil.PORTAL;
49      }
50  
51      protected void navigation() throws InterruptedException {
52          waitAndClickKRAD();
53          waitAndClickByXpath(VALIDATION_FRAMEWORK_DEMO_XPATH);
54          switchToWindow(KUALI_VIEW_WINDOW_TITLE);
55      }
56  
57      protected void testClientErrorsNav(Failable failable) throws Exception {
58          navigation();
59          testClientErrors();
60          passed();
61      }
62  
63      protected void testClientErrorsBookmark(Failable failable) throws Exception {
64          testClientErrors();
65          passed();
66      }
67  
68      protected void testClientErrors() throws Exception {
69          fireEvent("field1", "focus");
70          fireEvent("field1", "blur");
71          Thread.sleep(3000);
72          fireMouseOverEventByName("field1");
73          SeleneseTestBase.assertEquals("true", getAttributeByName("field1", "aria-invalid"));
74          assertAttributeClassRegexMatches("field1", REGEX_ERROR);
75          SeleneseTestBase.assertTrue(isTextPresent("Required"));
76  
77          fireMouseOverEventByName("field1");
78  
79          for (int second = 0;; second++) {
80              if (second >= 10) {
81                  SeleneseTestBase.fail(TIMEOUT_MESSAGE);
82              }
83  
84              try {
85                  if (isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) {
86                      break;
87                  }
88              } catch (Exception e) {}
89  
90              Thread.sleep(1000);
91          }
92  
93          SeleneseTestBase.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems  .uif-errorMessageItem-field"));
94  
95          waitAndTypeByName("field1", "a");
96          fireEvent("field1", "blur");
97          fireMouseOverEventByName("field1");
98  
99          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 }