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