001 /** 002 * Copyright 2005-2013 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 package edu.samplu.krad.validationmessagesview; 017 018 import com.thoughtworks.selenium.SeleneseTestBase; 019 import edu.samplu.common.Failable; 020 import edu.samplu.common.ITUtil; 021 import edu.samplu.common.WebDriverLegacyITBase; 022 import org.openqa.selenium.By; 023 024 /** 025 * Tests the Component section in Rice. 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029 public abstract class ClientErrorsAbstractSmokeTestBase extends WebDriverLegacyITBase { 030 031 /** 032 * "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start" 033 */ 034 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=Demo-ValidationLayout&methodToCall=start"; 035 036 protected void bookmark() { 037 open(ITUtil.getBaseUrlString() + BOOKMARK_URL); 038 } 039 040 /** 041 * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}. 042 * Bookmark Tests should override and return {@link edu.samplu.krad.validationmessagesview.ClientErrorsAbstractSmokeTestBase#BOOKMARK_URL} 043 * {@inheritDoc} 044 * @return 045 */ 046 @Override 047 public String getTestUrl() { 048 return ITUtil.PORTAL; 049 } 050 051 protected void navigation() throws InterruptedException { 052 waitAndClickKRAD(); 053 waitAndClickByXpath(VALIDATION_FRAMEWORK_DEMO_XPATH); 054 switchToWindow(KUALI_VIEW_WINDOW_TITLE); 055 } 056 057 protected void testClientErrorsNav(Failable failable) throws Exception { 058 navigation(); 059 testClientErrors(); 060 passed(); 061 } 062 063 protected void testClientErrorsBookmark(Failable failable) throws Exception { 064 testClientErrors(); 065 passed(); 066 } 067 068 protected void testClientErrors() throws Exception { 069 fireEvent("field1", "focus"); 070 fireEvent("field1", "blur"); 071 Thread.sleep(3000); 072 fireMouseOverEventByName("field1"); 073 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field1", "aria-invalid")); 074 assertAttributeClassRegexMatches("field1", REGEX_ERROR); 075 SeleneseTestBase.assertTrue(isTextPresent("Required")); 076 077 fireMouseOverEventByName("field1"); 078 079 for (int second = 0;; second++) { 080 if (second >= 10) { 081 SeleneseTestBase.fail(TIMEOUT_MESSAGE); 082 } 083 084 try { 085 if (isVisibleByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) { 086 break; 087 } 088 } catch (Exception e) {} 089 090 Thread.sleep(1000); 091 } 092 093 SeleneseTestBase.assertTrue(isVisible(".jquerybubblepopup-innerHtml > .uif-clientMessageItems .uif-errorMessageItem-field")); 094 095 waitAndTypeByName("field1", "a"); 096 fireEvent("field1", "blur"); 097 fireMouseOverEventByName("field1"); 098 099 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 Thread.sleep(500); 118 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field1' and @aria-invalid]")); 119 assertAttributeClassRegexMatches("field1", REGEX_VALID); 120 SeleneseTestBase.assertTrue(isTextPresent("Required")); 121 122 fireEvent("field2", "focus"); 123 fireEvent("field2", "blur"); 124 fireMouseOverEventByName("field2"); 125 Thread.sleep(500); 126 // SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-invalid")); 127 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field2", "aria-required")); 128 assertAttributeClassRegexMatches("field2", REGEX_ERROR); 129 SeleneseTestBase.assertTrue(isTextPresent("Required")); 130 131 fireEvent("field2", "focus"); 132 waitAndTypeByName("field2", "a"); 133 fireEvent("field2", "blur"); 134 Thread.sleep(500); 135 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field2' and @aria-invalid]")); 136 assertAttributeClassRegexMatches("field2", REGEX_VALID); 137 SeleneseTestBase.assertFalse(isElementPresentByXpath("//textarea[@name='field2']/../img[@alt='Error']")); 138 139 fireEvent("field3", "focus"); 140 fireEvent("field3", "blur"); 141 fireMouseOverEventByName("field3"); 142 Thread.sleep(500); 143 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field3", "aria-invalid")); 144 assertAttributeClassRegexMatches("field3", REGEX_ERROR); 145 SeleneseTestBase.assertTrue(isTextPresent("Required")); 146 147 fireEvent("field3", "focus"); 148 selectByName("field3", "Option 1"); 149 fireEvent("field3", "blur"); 150 Thread.sleep(500); 151 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field3' and @aria-invalid]")); 152 assertAttributeClassRegexMatches("field3", REGEX_VALID); 153 SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field3']/../img[@alt='Error']")); 154 155 fireEvent("field114", "focus"); 156 fireMouseOverEventByName("field114"); 157 driver.findElement(By.name("field114")).findElements(By.tagName("option")).get(0).click(); 158 fireEvent("field114", "blur"); 159 Thread.sleep(500); 160 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("field114", "aria-invalid")); 161 assertAttributeClassRegexMatches("field114", REGEX_ERROR); 162 SeleneseTestBase.assertTrue(isTextPresent("Required")); 163 164 fireEvent("field114", "focus"); 165 selectByName("field114", "Option 1"); 166 fireEvent("field114", "blur"); 167 Thread.sleep(500); 168 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field114' and @aria-invalid]")); 169 assertAttributeClassRegexMatches("field114", REGEX_VALID); 170 SeleneseTestBase.assertFalse(isElementPresentByXpath("//select[@name='field114']/../img[@alt='Error']")); 171 172 fireEvent("field117", "3", "focus"); 173 uncheckByXpath("//*[@name='field117' and @value='3']"); 174 fireEvent("field117", "blur"); 175 fireMouseOverEventByName("field117"); 176 177 for (int second = 0;; second++) { 178 if (second >= 10) { 179 SeleneseTestBase.fail(TIMEOUT_MESSAGE); 180 } 181 182 try { 183 if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) { 184 break; 185 } 186 } catch (Exception e) {} 187 188 Thread.sleep(1000); 189 } 190 191 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByXpath("//*[@name='field117' and @value='1']", 192 "aria-invalid")); 193 SeleneseTestBase.assertTrue(waitAndGetAttributeByXpath("//*[@name='field117' and @value='1']", "class").matches( 194 REGEX_ERROR)); 195 SeleneseTestBase.assertTrue(isTextPresent("Required")); 196 197 fireEvent("field117", "3", "focus"); 198 checkByXpath("//*[@name='field117' and @value='3']"); 199 fireEvent("field117", "3", "blur"); 200 201 for (int second = 0;; second++) { 202 if (second >= waitSeconds) { 203 SeleneseTestBase.fail(TIMEOUT_MESSAGE); 204 } 205 206 try { 207 if (!isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")) { 208 break; 209 } 210 } catch (Exception e) {} 211 212 Thread.sleep(1000); 213 } 214 215 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field117' and @value='3' and @aria-invalid]")); 216 SeleneseTestBase.assertTrue(waitAndGetAttributeByXpath("//*[@name='field117' and @value='3']", "class").matches(REGEX_VALID)); 217 SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field117']/../../../img[@alt='Error']")); 218 219 fireEvent("bField1", "focus"); 220 uncheckByName("bField1"); 221 fireEvent("bField1", "blur"); 222 fireMouseOverEventByName("bField1"); 223 Thread.sleep(500); 224 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByName("bField1", "aria-invalid")); 225 assertAttributeClassRegexMatches("bField1", REGEX_ERROR); 226 SeleneseTestBase.assertTrue(isTextPresent("Required")); 227 228 fireEvent("bField1", "focus"); 229 checkByName("bField1"); 230 fireEvent("bField1", "blur"); 231 Thread.sleep(500); 232 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='bField1' and @aria-invalid]")); 233 assertAttributeClassRegexMatches("bField1", REGEX_VALID); 234 SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='bField1' and following-sibling::img[@alt='Error']]")); 235 236 fireEvent("field115", "3", "focus"); 237 uncheckByXpath("//*[@name='field115' and @value='3']"); 238 uncheckByXpath("//*[@name='field115' and @value='4']"); 239 fireEvent("field115", "blur"); 240 fireMouseOverEventByName("field115"); 241 242 for (int second = 0;; second++) { 243 if (second >= waitSeconds) { 244 SeleneseTestBase.fail(TIMEOUT_MESSAGE); 245 } 246 247 try { 248 if (isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-kr-error-cs']")) { 249 break; 250 } 251 } catch (Exception e) {} 252 253 Thread.sleep(1000); 254 } 255 256 SeleneseTestBase.assertEquals("true", waitAndGetAttributeByXpath("//*[@name='field115' and @value='1']", 257 "aria-invalid")); 258 SeleneseTestBase.assertTrue(waitAndGetAttributeByXpath("//*[@name='field115' and @value='1']", "class").matches(REGEX_ERROR)); 259 SeleneseTestBase.assertTrue(isTextPresent("Required")); 260 261 fireEvent("field115", "3", "focus"); 262 checkByXpath("//*[@name='field115' and @value='3']"); 263 checkByXpath("//*[@name='field115' and @value='4']"); 264 fireEvent("field115", "blur"); 265 266 for (int second = 0;; second++) { 267 if (second >= waitSeconds) { 268 SeleneseTestBase.fail(TIMEOUT_MESSAGE); 269 } 270 271 try { 272 if (!isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")) { 273 break; 274 } 275 } catch (Exception e) {} 276 277 Thread.sleep(1000); 278 } 279 280 SeleneseTestBase.assertFalse(isElementPresentByXpath("//*[@name='field115' and @value='3' and @aria-invalid]")); 281 SeleneseTestBase.assertFalse(isElementPresentByXpath("//input[@name='field115']/../../../img[@alt='Error']")); 282 } 283 }