001 /** 002 * Copyright 2005-2014 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.sampleu.travel; 017 018 import org.kuali.rice.testtools.common.JiraAwareFailable; 019 import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase; 020 import org.openqa.selenium.By; 021 import org.openqa.selenium.WebElement; 022 023 /** 024 * Tests the Component section in Rice. 025 * 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028 public abstract class UifComponentValidationRegexPatternAftBase extends WebDriverLegacyITBase { 029 030 /** 031 * "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&readOnlyFields=field91" 032 */ 033 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&readOnlyFields=field91"; 034 035 @Override 036 protected String getBookmarkUrl() { 037 return BOOKMARK_URL; 038 } 039 040 protected void navigation() throws InterruptedException { 041 waitAndClickKRAD(); 042 waitAndClickByXpath(KITCHEN_SINK_XPATH); 043 switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH); 044 } 045 046 protected void testValidCharacterConstraintNav(JiraAwareFailable failable) throws Exception { 047 navigation(); 048 testValidCharacterConstraint(); 049 passed(); 050 } 051 052 protected void testValidCharacterConstraintBookmark(JiraAwareFailable failable) throws Exception { 053 testValidCharacterConstraint(); 054 passed(); 055 } 056 057 protected void testValidCharacterConstraint() throws Exception { 058 waitAndClickByLinkText("Validation"); 059 waitAndClickByLinkText("Validation - Regex"); 060 waitAndClickById("UifCompView-Navigation4"); 061 062 //---------------------------------------------Fixed Point------------------------------// 063 assertInvalidValidFieldValues("field50", new String[]{"123.123", "1234.4", "1234.434"}, new String[]{"123.67"}); 064 065 //---------------------------------------------Floating Point------------------------------// 066 assertInvalidValidFieldValues("field51", new String[]{"127.", "1234()98"}, new String[]{"-123.67"}); 067 068 //---------------------------------------------Integer Pattern constraint------------------------------// 069 assertInvalidValidFieldValues("field77", new String[]{"127.", "1234.4123", "123E123"}, new String[]{"-123"}); 070 071 //---------------------------------------------Phone Text------------------------------// 072 assertInvalidValidFieldValues("field52", new String[]{"1271231234", "123-123-123", "12-12-123445", "1234-12-1234", 073 "123.123.1234", "123-123-12345"}, new String[]{"123-123-1234"}); 074 075 //---------------------------------------------JavaClass Text------------------------------// 076 assertInvalidValidFieldValues("field53", new String[]{"127", "TestJava!@#Class", "Test JavaClass"}, new String[]{"TestJavaClass"}); 077 078 //---------------------------------------------Email Text------------------------------// 079 assertInvalidValidFieldValues("field54", new String[]{"123@123.123", "email.com@emailServer", "emailemailServer@.com"}, new String[]{"email@emailServer.com"}); 080 081 //---------------------------------------------URL pattern Text------------------------------// 082 assertInvalidValidFieldValues("field84", new String[]{"www.google.com", "https:www.google.com", "ftp://www.google.comsdfa123!#@", 083 "ftp:/www.google.coms"}, new String[]{"ftp://www.google.com", "https://www.google.com", "http://www.google.com"}); 084 085 //---------------------------------------------Date pattern Text------------------------------// 086 assertInvalidValidFieldValues("field55", new String[]{"12/12/2112 12:12:87 am", "12-12-2112 12:12 am", "12-12-2112 12:12", 087 "12/12/2112 12:12", "12-12-2112 12:12:78", "12 Sept", "Sept 12 12:12", "221299 12:12:13", "111222 12:12", "9/9/2012 12:12 am"}, 088 new String[]{"09/09/2012 12:12 pm", "090923", "Sept 12", "2034", "12/12/2012 23:12:59", "12-12-12 23:12:59", "121212 23:12:32", 089 "Sept 12 23:45:50", "2011 12:23:32"}); 090 091 092 //---------------------------------------------BasicDate pattern Text------------------------------// 093 assertInvalidValidFieldValues("field75", new String[]{"12122012", "13-12-34", "12:12:2034"}, new String[]{"12-12-2034"}); 094 095 //---------------------------------------------Time12H Pattern Text------------------------------// 096 assertInvalidValidFieldValues("field82", new String[]{"13:00:12", "09:00:", "3-00:12"}, new String[]{"3:00:34", "3:00"}); 097 098 //---------------------------------------------Time24H Pattern Text------------------------------// 099 assertInvalidValidFieldValues("field83", new String[]{"24:00:12", "14:00:", "13:00:76"}, new String[]{"13:00:23", "23:00:12"}); 100 101 //---------------------------------------------Timestamp pattern Text------------------------------// 102 assertInvalidValidFieldValues("field56", new String[]{"1000-12-12 12:12:12.103", "2000/12/12 12-12-12.87", 103 "2000/12/12 12-12-12.87", "2011-08-12 12:12:12", /*"2999-12-12 12:12:12.103"*/ }, new String[]{"2099-12-12 12:12:12.103"}); 104 105 //---------------------------------------------Year Pattern Text------------------------------// 106 assertInvalidValidFieldValues("field57", new String[]{"1599", "2200", 107 "20000", "-202"}, new String[]{"2000"}); 108 109 //---------------------------------------------Month Pattern Text------------------------------// 110 assertInvalidValidFieldValues("field58", new String[]{"0", "-12", "100"}, new String[]{"12"}); 111 112 //---------------------------------------------ZipCode Pattern Text------------------------------// 113 assertInvalidValidFieldValues("field61", new String[]{"123", "2341 12", "0-1231"}, new String[]{"12345"}); 114 115 //---------------------------------------------Alpha Numeric w/o options Text------------------------------// 116 assertInvalidValidFieldValues("field62", new String[]{"123 23 @#", "-asd123", "asd/123"}, new String[]{"asd123"}); 117 118 //---------------------------------------------Alpha Numeric with options Text------------------------------// 119 assertInvalidValidFieldValues("field63", new String[]{"123^we", "-123_asd", "123 23 @#"}, new String[]{"as_de 456/123"}); 120 121 //---------------------------------------------Alpha with Whitespace and commas Text------------------------------// 122 assertInvalidValidFieldValues("field64", new String[]{"123^we", "asd_pqr", "asd/def"}, new String[]{"asd ,pqr"}); 123 124 //---------------------------------------------AlphaPatterrn with disallowed charset Text------------------------------// 125 assertInvalidValidFieldValues("field76", new String[]{"123", "`abcd`", "|abcd|", "~abcd~"}, new String[]{" ab_c d_ef "}); 126 127 //---------------------------------------------Anything with No Whitespace Text------------------------------// 128 assertInvalidValidFieldValues("field65", new String[]{"123 ^we"}, new String[]{"123^we!@#^&*~:"}); 129 130 //---------------------------------------------CharacterSet Text------------------------------// 131 assertInvalidValidFieldValues("field66", new String[]{"123 ^we", "123_^we", "abc ABC"}, new String[]{"aAbBcC"}); 132 133 //---------------------------------------------Numeric Character Text------------------------------// 134 assertInvalidValidFieldValues("field67", new String[]{"123 ^we", "123/10", "(123.00)"}, new String[]{"(12-3)"}); 135 136 //---------------------------------------------Valid Chars Custom Text------------------------------// 137 assertInvalidValidFieldValues("field68", new String[]{ "123.123", "a.b", "123 qwe", "5.a", "a.0,b.4"}, new String[]{"a.0"}); 138 } 139 140 private boolean isErrorAttributeTrue(String fieldName) throws Exception { 141 Thread.sleep(500); 142 boolean valid = false; 143 144 for (int second = 0; second < 5; second++) { 145 if ((valid = validateErrorAttribute(fieldName)) == true) { 146 break; 147 } 148 } 149 150 return valid; 151 } 152 153 private boolean validateErrorAttribute(String fieldName) throws InterruptedException { 154 try { 155 WebElement field = findElement(By.name(fieldName)); 156 return "true".equals(field.getAttribute("aria-invalid")); 157 } catch (Exception e) { 158 // don't fail here, we're in a loop let the caller decide when to fail 159 } 160 161 Thread.sleep(1000); 162 163 return false; 164 } 165 166 private void assertInvalidValidFieldValues(String fieldNameToTest, String[] invalids, String[] valids) throws Exception { 167 for (String invalid : invalids) { 168 clearTextByName(fieldNameToTest); 169 waitAndTypeByName(fieldNameToTest, invalid); 170 fireEvent(fieldNameToTest, "blur"); 171 if (!isErrorAttributeTrue(fieldNameToTest)) { 172 jiraAwareFail(invalid + " expected to be invalid for field name " + fieldNameToTest); 173 } 174 clearTextByName(fieldNameToTest); 175 } 176 177 for (String valid : valids) { 178 clearTextByName(fieldNameToTest); 179 waitAndTypeByName(fieldNameToTest, valid); 180 fireEvent(fieldNameToTest, "blur"); 181 if (isErrorAttributeTrue(fieldNameToTest)) { 182 jiraAwareFail(valid + " expected to be valid for field name " + fieldNameToTest); 183 } 184 clearTextByName(fieldNameToTest); 185 } 186 } 187 }