001 /*
002 * Copyright 2006-2012 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 */
016
017 package edu.samplu.krad.validationmessagesview;
018
019 import edu.samplu.common.WebDriverLegacyITBase;
020
021 import junit.framework.Assert;
022 import org.junit.Test;
023 import org.openqa.selenium.By;
024
025 /**
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028 public class ClientErrorsLegacyIT extends WebDriverLegacyITBase {
029 @Override
030 public String getTestUrl() {
031 return "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start";
032 }
033
034 @Test
035 public void testClientErrors() throws Exception {
036 fireEvent("field1", "focus");
037 waitAndTypeByName("field1","");
038 fireEvent("field1", "blur");
039 Assert.assertEquals("true", getAttributeByName("field1","aria-invalid"));
040 Assert.assertTrue(getAttributeByName("field1","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
041 Assert.assertTrue(isElementPresentByXpath("//textarea[@name='field1']/../../img[@alt='Error']"));
042 fireEvent("field1", "focus");
043 for (int second = 0; ; second++) {
044 if (second >= 60) {
045 Assert.fail("timeout");
046 }
047 try {
048 if (isVisible(".jquerybubblepopup-innerHtml")) {
049 break;
050 }
051 } catch (Exception e) {
052 }
053 Thread.sleep(1000);
054 }
055
056 Assert.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field"));
057 waitAndTypeByName("field1", "a");
058 fireEvent("field1", "blur");
059 fireEvent("field1", "focus");
060 for (int second = 0; ; second++) {
061 if (second >= 60) {
062 Assert.fail("timeout");
063 }
064 try {
065 if (!isVisible(".jquerybubblepopup-innerHtml")) {
066 break;
067 }
068 } catch (Exception e) {
069 }
070 Thread.sleep(1000);
071 }
072
073 Assert.assertFalse(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems"));
074 fireEvent("field1", "blur");
075 Assert.assertFalse(isElementPresentByXpath("//*[@name='field1' and @aria-invalid]"));
076 Assert.assertTrue(getAttributeByName("field1","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
077 Assert.assertFalse(isElementPresentByXpath("//textarea[@name='field1']/../img[@alt='Error']"));
078 fireEvent("field2", "focus");
079 waitAndTypeByName("field2", "");
080 fireEvent("field2", "blur");
081 Assert.assertEquals("true", getAttributeByName("field2","aria-invalid"));
082 Assert.assertTrue(getAttributeByName("field2","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
083 Assert.assertTrue(isElementPresentByXpath("//input[@name='field2']/../img[@alt='Error']"));
084 fireEvent("field2", "focus");
085 waitAndTypeByName("field2", "a");
086 fireEvent("field2", "blur");
087 Assert.assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]"));
088 Assert.assertTrue(getAttributeByName("field2","class").matches("^[\\s\\S]*valid[\\s\\S]*$"));
089 Assert.assertFalse(isElementPresentByXpath("//textarea[@name='field2']/../img[@alt='Error']"));
090 fireEvent("field3", "focus");
091 selectByName("field3", "");
092 fireEvent("field3", "blur");
093 Assert.assertEquals("true", getAttributeByName("field3","aria-invalid"));
094 Assert.assertTrue(getAttributeByName("field3","class").matches("^[\\s\\S]*error[\\s\\S]*$"));
095 Assert.assertTrue(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']"));
096 fireEvent("field3", "focus");
097 selectByName("field3", "Option 1");
098 fireEvent("field3", "blur");
099 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 }