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 017 package edu.samplu.krad.compview; 018 019 import com.thoughtworks.selenium.SeleneseTestBase; 020 import edu.samplu.common.SmokeTestBase; 021 import org.junit.Test; 022 023 /** 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 */ 026 public class ConstraintsSmokeTest extends SmokeTestBase { 027 028 /** 029 * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3 030 */ 031 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3"; 032 033 @Override 034 protected String getBookmarkUrl() { 035 return BOOKMARK_URL; 036 } 037 038 @Override 039 protected void navigate() throws Exception { 040 waitAndClickKRAD(); 041 waitAndClickByXpath(KITCHEN_SINK_XPATH); 042 switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH); 043 waitAndClickByLinkText("Validation"); 044 } 045 046 protected void testConstraintsField9() throws Exception { 047 testField9FocusBlur(); 048 passed(); 049 } 050 051 private void testPreRequisiteConstraint() throws Exception { 052 fireEvent("field6", "focus"); 053 waitAndTypeByName("field6", "A"); 054 fireEvent("field6", "blur"); 055 waitAndTypeByName("field7", ""); 056 fireEvent("field7", "blur"); 057 assertAttributeClassRegexMatches("field7", REGEX_ERROR); 058 059 waitAndTypeByName("field7", "B"); 060 fireEvent("field7", "blur"); 061 assertAttributeClassRegexMatches("field7", REGEX_VALID); 062 063 waitAndTypeByName("field8", ""); 064 fireEvent("field8", "blur"); 065 assertAttributeClassRegexMatches("field8", REGEX_ERROR); 066 067 clearTextByName("field8"); 068 waitAndTypeByName("field8", "C"); 069 fireEvent("field8", "blur"); 070 assertAttributeClassRegexMatches("field8", REGEX_VALID); 071 072 clearTextByName("field6"); 073 waitAndTypeByName("field6", ""); 074 fireEvent("field6", "blur"); 075 assertAttributeClassRegexMatches("field6", REGEX_ERROR); 076 077 clearTextByName("field7"); 078 waitAndTypeByName("field7", ""); 079 fireEvent("field7", "blur"); 080 assertAttributeClassRegexMatches("field7", REGEX_VALID); 081 082 clearTextByName("field8"); 083 waitAndTypeByName("field8", ""); 084 fireEvent("field8", "blur"); 085 assertAttributeClassRegexMatches("field6", REGEX_VALID); 086 assertAttributeClassRegexMatches("field7", REGEX_VALID); 087 assertAttributeClassRegexMatches("field8", REGEX_VALID); 088 089 clearTextByName("field8"); 090 waitAndTypeByName("field8", "C"); 091 fireEvent("field8", "blur"); 092 assertAttributeClassRegexMatches("field6", REGEX_ERROR); 093 assertAttributeClassRegexMatches("field7", REGEX_VALID); 094 assertAttributeClassRegexMatches("field8", REGEX_ERROR); 095 096 clearTextByName("field6"); 097 waitAndTypeByName("field6", "A"); 098 fireEvent("field6", "blur"); 099 assertAttributeClassRegexMatches("field6", REGEX_VALID); 100 assertAttributeClassRegexMatches("field7", REGEX_ERROR); 101 assertAttributeClassRegexMatches("field8", REGEX_VALID); 102 passed(); 103 } 104 105 private void testField9FocusBlur() throws InterruptedException { 106 fireEvent("field9", "focus"); 107 waitAndTypeByName("field9", "1"); 108 fireEvent("field9", "blur"); 109 assertAttributeClassRegexMatches("field9", REGEX_ERROR); // Sometimes get a failure here. 110 111 fireEvent("field9", "focus"); 112 clearTextByName("field9"); 113 waitAndTypeByName("field9", "12345"); 114 fireEvent("field9", "blur"); 115 assertAttributeClassRegexMatches("field9", REGEX_VALID); 116 } 117 118 protected void testConstraints() throws Exception { 119 checkForIncidentReport("testConstraints"); 120 121 // TODO break out into smaller methods, especially if a test flaps. https://jira.kuali.org/browse/KULRICE-9711 122 fireEvent("field10", "focus"); 123 waitAndTypeByName("field10", "2"); 124 fireEvent("field10", "blur"); 125 assertAttributeClassRegexMatches("field10", REGEX_ERROR); 126 127 fireEvent("field10", "focus"); 128 clearTextByName("field10"); 129 waitAndTypeByName("field10", "51"); 130 fireEvent("field10", "blur"); 131 assertAttributeClassRegexMatches("field10", REGEX_ERROR); 132 133 fireEvent("field10", "focus"); 134 clearTextByName("field10"); 135 waitAndTypeByName("field10", "25"); 136 fireEvent("field10", "blur"); 137 assertAttributeClassRegexMatches("field10", REGEX_VALID); 138 139 waitAndTypeByName("field14", "A"); 140 fireEvent("field14", "blur"); 141 142 assertAttributeClassRegexMatches("field14", REGEX_ERROR); 143 clearTextByName("field11"); 144 waitAndTypeByName("field11", "A"); 145 fireEvent("field11", "blur"); 146 assertAttributeClassRegexMatches("field11", REGEX_VALID); 147 assertAttributeClassRegexMatches("field14", REGEX_VALID); 148 149 clearTextByName("field11"); 150 waitAndTypeByName("field11", ""); 151 fireEvent("field11", "blur"); 152 assertAttributeClassRegexMatches("field14", REGEX_ERROR); 153 154 clearTextByName("field12"); 155 waitAndTypeByName("field12", "A"); 156 fireEvent("field12", "blur"); 157 assertAttributeClassRegexMatches("field14", REGEX_ERROR); 158 159 clearTextByName("field13"); 160 waitAndTypeByName("field13", "A"); 161 fireEvent("field13", "blur"); 162 assertAttributeClassRegexMatches("field13", REGEX_VALID); 163 assertAttributeClassRegexMatches("field14", REGEX_VALID); 164 165 clearTextByName("field11"); 166 waitAndTypeByName("field11", "A"); 167 fireEvent("field11", "blur"); 168 assertAttributeClassRegexMatches("field11", REGEX_VALID); 169 assertAttributeClassRegexMatches("field14", REGEX_VALID); 170 171 waitAndTypeByName("field18", "A"); 172 fireEvent("field18", "blur"); 173 assertAttributeClassRegexMatches("field18", REGEX_ERROR); 174 175 waitAndTypeByName("field15", "A"); 176 fireEvent("field15", "blur"); 177 assertAttributeClassRegexMatches("field15", REGEX_VALID); 178 assertAttributeClassRegexMatches("field18", REGEX_VALID); 179 180 clearTextByName("field15"); 181 waitAndTypeByName("field15", ""); 182 fireEvent("field15", "blur"); 183 assertAttributeClassRegexMatches("field18", REGEX_ERROR); 184 185 clearTextByName("field16"); 186 waitAndTypeByName("field16", "A"); 187 fireEvent("field16", "blur"); 188 assertAttributeClassRegexMatches("field18", REGEX_ERROR); 189 190 clearTextByName("field17"); 191 waitAndTypeByName("field17", "A"); 192 fireEvent("field17", "blur"); 193 assertAttributeClassRegexMatches("field17", REGEX_VALID); 194 assertAttributeClassRegexMatches("field18", REGEX_VALID); 195 196 clearTextByName("field15"); 197 waitAndTypeByName("field15", "A"); 198 fireEvent("field15", "blur"); 199 assertAttributeClassRegexMatches("field18", REGEX_ERROR); 200 201 waitAndTypeByName("field23", "A"); 202 fireEvent("field23", "blur"); 203 assertAttributeClassRegexMatches("field23", REGEX_ERROR); 204 205 clearTextByName("field19"); 206 waitAndTypeByName("field19", "A"); 207 fireEvent("field19", "blur"); 208 assertAttributeClassRegexMatches("field23", REGEX_VALID); 209 210 clearTextByName("field19"); 211 waitAndTypeByName("field19", ""); 212 fireEvent("field19", "blur"); 213 waitAndTypeByName("field20", "B"); 214 fireEvent("field20", "blur"); 215 assertAttributeClassRegexMatches("field23", REGEX_VALID); 216 217 clearTextByName("field20"); 218 waitAndTypeByName("field20", ""); 219 fireEvent("field20", "blur"); 220 assertAttributeClassRegexMatches("field23", REGEX_ERROR); 221 222 clearTextByName("field21"); 223 waitAndTypeByName("field21", "C"); 224 fireEvent("field21", "blur"); 225 assertAttributeClassRegexMatches("field23", REGEX_ERROR); 226 227 clearTextByName("field22"); 228 waitAndTypeByName("field22", "D"); 229 fireEvent("field22", "blur"); 230 assertAttributeClassRegexMatches("field23", REGEX_VALID); 231 232 clearTextByName("field19"); 233 waitAndTypeByName("field19", "D"); 234 fireEvent("field19", "blur"); 235 assertAttributeClassRegexMatches("field23", REGEX_VALID); 236 237 clearTextByName("field20"); 238 waitAndTypeByName("field20", "D"); 239 fireEvent("field20", "blur"); 240 assertAttributeClassRegexMatches("field23", REGEX_VALID); 241 242 checkByXpath("//*[@name='field24' and @value='case1']"); 243 clearTextByName("field25"); 244 waitAndTypeByName("field25", ""); 245 fireEvent("field25", "blur"); 246 assertAttributeClassRegexMatches("field25", REGEX_ERROR); 247 248 checkByXpath("//*[@name='field24' and @value='case4']"); 249 fireEvent("field24", "blur"); 250 251 for (int second = 0;; second++) { 252 if (second >= waitSeconds) { 253 SeleneseTestBase.fail("timeout"); 254 } 255 try { 256 if (waitAndGetAttributeByName("field25", "class").matches(REGEX_VALID)) { 257 break; 258 } 259 } catch (Exception e) {} 260 Thread.sleep(1000); 261 } 262 263 assertAttributeClassRegexMatches("field25", REGEX_VALID); 264 265 checkByXpath("//*[@name='field24' and @value='case1']"); 266 fireEvent("field24", "blur"); 267 clearTextByName("field25"); 268 waitAndTypeByName("field25", "$100"); 269 fireEvent("field25", "blur"); 270 271 for (int second = 0;; second++) { 272 if (second >= waitSeconds) { 273 SeleneseTestBase.fail("timeout"); 274 } 275 try { 276 if (waitAndGetAttributeByName("field25", "class").matches(REGEX_VALID)) { 277 break; 278 } 279 } catch (Exception e) {} 280 Thread.sleep(1000); 281 } 282 283 assertAttributeClassRegexMatches("field25", REGEX_VALID); 284 285 checkByXpath("//*[@name='field24' and @value='case2']"); 286 fireEvent("field24", "blur"); 287 288 for (int second = 0;; second++) { 289 if (second >= waitSeconds) { 290 SeleneseTestBase.fail("timeout"); 291 } 292 try { 293 if (waitAndGetAttributeByName("field25", "class").matches(REGEX_ERROR)) { 294 break; 295 } 296 } catch (Exception e) {} 297 Thread.sleep(1000); 298 } 299 300 assertAttributeClassRegexMatches("field25", REGEX_ERROR); 301 302 clearTextByName("field25"); 303 waitAndTypeByName("field25", "A100"); 304 fireEvent("field25", "blur"); 305 assertAttributeClassRegexMatches("field25", REGEX_VALID); 306 307 checkByXpath("//*[@name='field24' and @value='case3']"); 308 fireEvent("field24", "blur"); 309 clearTextByName("field26"); 310 waitAndTypeByName("field26", "6000"); 311 fireEvent("field26", "blur"); 312 313 for (int second = 0;; second++) { 314 if (second >= waitSeconds) { 315 SeleneseTestBase.fail("timeout"); 316 } 317 try { 318 if (waitAndGetAttributeByName("field26", "class").matches(REGEX_ERROR)) { 319 break; 320 } 321 } catch (Exception e) {} 322 Thread.sleep(1000); 323 } 324 325 assertAttributeClassRegexMatches("field26", REGEX_ERROR); 326 327 clearTextByName("field26"); 328 waitAndTypeByName("field26", "501"); 329 fireEvent("field26", "blur"); 330 assertAttributeClassRegexMatches("field26", REGEX_ERROR); 331 332 clearTextByName("field26"); 333 waitAndTypeByName("field26", "499"); 334 fireEvent("field26", "blur"); 335 assertAttributeClassRegexMatches("field26", REGEX_VALID); 336 337 clearTextByName("field26"); 338 waitAndTypeByName("field26", "6000"); 339 fireEvent("field26", "blur"); 340 checkByXpath("//*[@name='field24' and @value='case3']"); 341 fireEvent("field24", "blur"); 342 343 for (int second = 0;; second++) { 344 if (second >= waitSeconds) { 345 SeleneseTestBase.fail("timeout"); 346 } 347 try { 348 if (waitAndGetAttributeByName("field26", "class").matches(REGEX_ERROR)) { 349 break; 350 } 351 } catch (Exception e) {} 352 Thread.sleep(1000); 353 } 354 355 assertAttributeClassRegexMatches("field26", REGEX_ERROR); 356 357 checkByXpath("//*[@name='field24' and @value='case4']"); 358 clearTextByName("field27"); 359 waitAndTypeByName("field27", "A"); 360 fireEvent("field27", "blur"); 361 clearTextByName("field28"); 362 waitAndTypeByName("field28", ""); 363 fireEvent("field28", "blur"); 364 365 for (int second = 0;; second++) { 366 if (second >= waitSeconds) { 367 SeleneseTestBase.fail("timeout"); 368 } 369 try { 370 if (waitAndGetAttributeByName("field28", "class").matches(REGEX_ERROR)) { 371 break; 372 } 373 } catch (Exception e) {} 374 Thread.sleep(1000); 375 } 376 377 assertAttributeClassRegexMatches("field28", REGEX_ERROR); 378 379 checkByXpath("//*[@name='field24' and @value='case3']"); 380 fireEvent("field24", "blur"); 381 382 for (int second = 0;; second++) { 383 if (second >= waitSeconds) { 384 SeleneseTestBase.fail("timeout"); 385 } 386 try { 387 if (waitAndGetAttributeByName("field28", "class").matches(REGEX_VALID)) { 388 break; 389 } 390 } catch (Exception e) {} 391 Thread.sleep(1000); 392 } 393 394 assertAttributeClassRegexMatches("field28", REGEX_VALID); 395 396 clearTextByName("field28"); 397 waitAndTypeByName("field28", "B"); 398 fireEvent("field28", "blur"); 399 checkByXpath("//*[@name='field24' and @value='case4']"); 400 fireEvent("field24", "blur"); 401 402 for (int second = 0;; second++) { 403 if (second >= waitSeconds) { 404 SeleneseTestBase.fail("timeout"); 405 } 406 try { 407 if (waitAndGetAttributeByName("field28", "class").matches(REGEX_VALID)) { 408 break; 409 } 410 } catch (Exception e) {} 411 Thread.sleep(1000); 412 } 413 414 assertAttributeClassRegexMatches("field28", REGEX_VALID); 415 416 clearTextByName("field31"); 417 waitAndTypeByName("field31", "B"); 418 clearTextByName("field32"); 419 waitAndTypeByName("field32", "B"); 420 waitAndTypeByName("field33", ""); 421 fireEvent("field33", "blur"); 422 assertAttributeClassRegexMatches("field33", REGEX_ERROR); 423 424 clearTextByName("field33"); 425 waitAndTypeByName("field33", "B"); 426 fireEvent("field33", "blur"); 427 assertAttributeClassRegexMatches("field33", REGEX_VALID); 428 429 clearTextByName("field32"); 430 waitAndTypeByName("field32", "A"); 431 clearTextByName("field33"); 432 waitAndTypeByName("field33", ""); 433 fireEvent("field33", "blur"); 434 assertAttributeClassRegexMatches("field33", REGEX_VALID); 435 } 436 437 @Test 438 public void testConstraintsBookmark() throws Exception { 439 testConstraints(); 440 passed(); 441 } 442 443 @Test 444 public void testConstraintsField9Bookmark() throws Exception { 445 testConstraintsField9(); 446 passed(); 447 } 448 449 @Test 450 public void testPreRequisiteConstraintBookmark() throws Exception { 451 testPreRequisiteConstraint(); 452 passed(); 453 } 454 455 @Test 456 public void testConstraintsNav() throws Exception { 457 testConstraints(); 458 passed(); 459 } 460 461 @Test 462 public void testConstraintsField9Nav() throws Exception { 463 testConstraintsField9(); 464 passed(); 465 } 466 467 @Test 468 public void testPreRequisiteConstraintNav() throws Exception { 469 testPreRequisiteConstraint(); 470 passed(); 471 } 472 }