View Javadoc

1   /*
2    * Copyright 2006-2012 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  
17  package edu.samplu.krad.validationmessagesview;
18  
19  import edu.samplu.common.WebDriverLegacyITBase;
20  
21  import junit.framework.Assert;
22  import org.junit.Test;
23  import org.openqa.selenium.By;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class ClientErrorsLegacyIT extends WebDriverLegacyITBase {
29      @Override
30      public String getTestUrl() {
31          return "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start";
32      }
33  
34      @Test
35      public void testClientErrors() throws Exception {
36          fireEvent("field1", "focus");
37          waitAndTypeByName("field1","");
38          fireEvent("field1", "blur");
39          Assert.assertEquals("true", getAttributeByName("field1","aria-invalid"));
40          Assert.assertTrue(getAttributeByName("field1","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
41          Assert.assertTrue(isElementPresentByXpath("//textarea[@name='field1']/../../img[@alt='Error']"));
42          fireEvent("field1", "focus");
43          for (int second = 0; ; second++) {
44              if (second >= 60) {
45                  Assert.fail("timeout");
46              }
47              try {
48                  if (isVisible(".jquerybubblepopup-innerHtml")) {
49                      break;
50                  }
51              } catch (Exception e) {
52              }
53              Thread.sleep(1000);
54          }
55  
56          Assert.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems  .uif-errorMessageItem-field"));
57          waitAndTypeByName("field1", "a");
58          fireEvent("field1", "blur");
59          fireEvent("field1", "focus");
60          for (int second = 0; ; second++) {
61              if (second >= 60) {
62                  Assert.fail("timeout");
63              }
64              try {
65                  if (!isVisible(".jquerybubblepopup-innerHtml")) {
66                      break;
67                  }
68              } catch (Exception e) {
69              }
70              Thread.sleep(1000);
71          }
72  
73          Assert.assertFalse(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
74          fireEvent("field1", "blur");
75          Assert.assertFalse(isElementPresentByXpath("//*[@name='field1' and @aria-invalid]"));
76          Assert.assertTrue(getAttributeByName("field1","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
77          Assert.assertFalse(isElementPresentByXpath("//textarea[@name='field1']/../img[@alt='Error']"));
78          fireEvent("field2", "focus");
79          waitAndTypeByName("field2", "");
80          fireEvent("field2", "blur");
81          Assert.assertEquals("true", getAttributeByName("field2","aria-invalid"));
82          Assert.assertTrue(getAttributeByName("field2","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
83          Assert.assertTrue(isElementPresentByXpath("//input[@name='field2']/../img[@alt='Error']"));
84          fireEvent("field2", "focus");
85          waitAndTypeByName("field2", "a");
86          fireEvent("field2", "blur");
87          Assert.assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
88          Assert.assertTrue(getAttributeByName("field2","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
89          Assert.assertFalse(isElementPresentByXpath("//textarea[@name='field2']/../img[@alt='Error']"));
90          fireEvent("field3", "focus");
91          selectByName("field3", "");
92          fireEvent("field3", "blur");
93          Assert.assertEquals("true", getAttributeByName("field3","aria-invalid"));
94          Assert.assertTrue(getAttributeByName("field3","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
95          Assert.assertTrue(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']"));
96          fireEvent("field3", "focus");
97          selectByName("field3", "Option 1");
98          fireEvent("field3", "blur");
99          Assert.assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]"));
100         Assert.assertTrue(getAttributeByName("field3","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
101         Assert.assertFalse(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']"));
102         fireEvent("field114", "focus");
103    //    removeAllSelectionsByName("field114");
104         driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click();
105         fireEvent("field114", "blur");
106         Assert.assertEquals("true", getAttributeByName("field114","aria-invalid"));
107         Assert.assertTrue(getAttributeByName("field114","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
108         Assert.assertTrue(isElementPresentByXpath("//select[@name='field114']/../img[@alt='Error']"));
109         fireEvent("field114", "focus");
110         selectByName("field114", "Option 1");
111         fireEvent("field114", "blur");
112         Assert.assertFalse(isElementPresentByXpath("//*[@name='field114' and @aria-invalid]"));
113         Assert.assertTrue(getAttributeByName("field114","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
114         Assert.assertFalse(isElementPresentByXpath("//select[@name='field114']/../img[@alt='Error']"));
115         fireEvent("field117", "3", "focus");
116         uncheckByXpath("//*[@name='field117' and @value='3']");
117         fireEvent("field117", "blur");
118         for (int second = 0; ; second++) {
119             if (second >= 10) {
120                 Assert.fail("timeout");
121             }
122             try {
123                 if (isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) {
124                     break;
125                 }
126             } catch (Exception e) {
127             }
128             Thread.sleep(1000);
129         }
130 
131         Assert.assertEquals("true", getAttributeByXpath("//*[@name='field117' and @value='1']","aria-invalid"));
132         Assert.assertTrue(getAttributeByXpath("//*[@name='field117' and @value='1']","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
133         Assert.assertTrue(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']"));
134         fireEvent("field117", "3", "focus");
135         checkByXpath("//*[@name='field117' and @value='3']");
136         fireEvent("field117", "3", "blur");
137         for (int second = 0; ; second++) {
138             if (second >= 60) {
139                 Assert.fail("timeout");
140             }
141             try {
142                 if (!isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) {
143                     break;
144                 }
145             } catch (Exception e) {
146             }
147             Thread.sleep(1000);
148         }
149 
150         Assert.assertFalse(isElementPresentByXpath("//*[@name='field117' and @value='3' and @aria-invalid]"));
151         Assert.assertTrue(getAttributeByXpath("//*[@name='field117' and @value='3']","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
152         Assert.assertFalse(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']"));
153         fireEvent("bField1", "focus");
154         uncheckByName("bField1");
155         fireEvent("bField1", "blur");
156         Assert.assertEquals("true", getAttributeByName("bField1","aria-invalid"));
157         Assert.assertTrue(getAttributeByName("bField1","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
158         Assert.assertTrue(isElementPresentByXpath(
159                 "//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
160         fireEvent("bField1", "focus");
161         checkByName("bField1");
162         fireEvent("bField1", "blur");
163         Assert.assertFalse(isElementPresentByXpath("//*[@name='bField1' and @aria-invalid]"));
164         Assert.assertTrue(getAttributeByName("bField1","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
165         Assert.assertFalse(isElementPresentByXpath(
166                 "//input[@name='bField1' and following-sibling::img[@alt='Error']]"));
167         fireEvent("field115", "3", "focus");
168         uncheckByXpath("//*[@name='field115' and @value='3']");
169         uncheckByXpath("//*[@name='field115' and @value='4']");
170         fireEvent("field115", "blur");
171         for (int second = 0; ; second++) {
172             if (second >= 60) {
173                 Assert.fail("timeout");
174             }
175             try {
176                 if (isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) {
177                     break;
178                 }
179             } catch (Exception e) {
180             }
181             Thread.sleep(1000);
182         }
183 
184         Assert.assertEquals("true", getAttributeByXpath("//*[@name='field115' and @value='1']","aria-invalid"));
185         Assert.assertTrue(getAttributeByXpath("//*[@name='field115' and @value='1']","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
186         Assert.assertTrue(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']"));
187         fireEvent("field115","3", "focus");
188         checkByXpath("//*[@name='field115' and @value='3']");
189         checkByXpath("//*[@name='field115' and @value='4']");
190         fireEvent("field115", "blur");
191         for (int second = 0; ; second++) {
192             if (second >= 60) {
193                 Assert.fail("timeout");
194             }
195             try {
196                 if (!isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) {
197                     break;
198                 }
199             } catch (Exception e) {
200             }
201             Thread.sleep(1000);
202         }
203 
204         Assert.assertFalse(isElementPresentByXpath("//*[@name='field115' and @value='3' and @aria-invalid]"));
205         Assert.assertFalse(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']"));
206         passed();
207     }
208 }