View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.library.validation;
17  
18  import org.junit.Test;
19  
20  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
21  import org.openqa.selenium.By;
22  
23  /**
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class LibraryValidationMustOccurConstraintsAft extends WebDriverLegacyITBase {
27  
28      /**
29       * /kr-krad/kradsampleapp?viewId=Demo-MustOccurConstraintView&methodToCall=start
30       */
31      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-MustOccurConstraintView&methodToCall=start";
32  
33      /**
34       *   1-2 of the following must occur: (Field 1A) OR (Field 2A and Field 2B)
35       */
36      private static final String EXAMPLE1_VALIDATION_MESSAGE="  1-2 of the following must occur: (Field 1A) OR (Field 2A and Field 2B)";
37      
38      /**
39       *   The following must occur: (Field 1A) OR (Field 2A and Field 2B)
40       */
41      private static final String EXAMPLE2_VALIDATION_MESSAGE="  The following must occur: (Field 1A) OR (Field 2A and Field 2B)";
42      
43      /**
44       *   1-2 of the following must occur: (Field 1A or Field 1B) OR (Field 2A and Field 2B)
45       */
46      private static final String EXAMPLE3_VALIDATION_MESSAGE="  1-2 of the following must occur: (Field 1A or Field 1B) OR (Field 2A and Field 2B)";
47      
48      /**
49       * //input[@name='inputField4' and @class='uif-textControl dependsOn-inputField1 dependsOn-inputField2 dependsOn-inputField3 dirty error']
50       */
51      private static final String EXAMPLE1_ERROR_XPATH="//input[@name='inputField4' and @class='error']";
52      
53      /**
54       * //input[@name='inputField8' and @class='uif-textControl dependsOn-inputField5 dependsOn-inputField6 dependsOn-inputField7 dirty error']
55       */
56      private static final String EXAMPLE2_ERROR_XPATH="//input[@name='inputField8' and @class='error']";
57      
58      /**
59       * //input[@name='inputField13' and @class='uif-textControl dependsOn-inputField9 dependsOn-inputField10 dependsOn-inputField11 dependsOn-inputField12 dirty error']
60       */
61      private static final String EXAMPLE3_ERROR_XPATH="//input[@name='inputField13' and @class='error']";
62   
63      @Override
64      protected String getBookmarkUrl() {
65          return BOOKMARK_URL;
66      }
67  
68      @Override
69      protected void navigate() throws Exception {
70          waitAndClickLibraryLink();
71          waitAndClickByLinkText("Validation");
72          waitAndClickByLinkText("Must Occur Constraint");
73      }
74  
75      protected void testValidationMustOccurConstraintsExample1() throws Exception {
76          waitAndClickByLinkText("Example 1");
77  
78         //Scenario-1
79          assertFocusTypeBlurError("inputField4", "a");
80          fireMouseOverEventByName("inputField4");
81          assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
82         
83          //Scenario-2
84          waitAndTypeByName("inputField1","a");
85          waitAndTypeByName("inputField2","");
86          if(isElementPresentByXpath(EXAMPLE1_ERROR_XPATH)) {
87              jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
88          }
89         
90          //Scenario-3
91          clearTextByName("inputField1");
92          waitAndTypeByName("inputField4","a");
93          waitAndTypeByName("inputField2", "a");
94          waitAndTypeByName("inputField1","");
95          String id = findElement(By.name("inputField4")).getAttribute("id");
96          assertTrue(findElement(By.id(id)).getAttribute("class").contains("error"));
97          fireEvent("inputField1", "blur");
98          fireMouseOverEventByName("inputField4");
99          assertTextPresent(EXAMPLE1_VALIDATION_MESSAGE);
100        
101         //Scenario-4
102         waitAndTypeByName("inputField3","a");
103         waitAndTypeByName("inputField1","");
104         if(isElementPresentByXpath(EXAMPLE1_ERROR_XPATH)) {
105             jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
106         }
107     }
108     
109     protected void testValidationMustOccurConstraintsExample2() throws Exception {
110         waitAndClickByLinkText("Example 2");
111         
112         //Scenario-1
113         assertFocusTypeBlurError("inputField8","a");
114         fireMouseOverEventByName("inputField8");
115         assertTextPresent(EXAMPLE2_VALIDATION_MESSAGE);
116         
117         //Scenario-2
118         waitAndTypeByName("inputField5","a");
119         waitAndTypeByName("inputField6","");
120         if(isElementPresentByXpath(EXAMPLE2_ERROR_XPATH)) {
121             jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
122         }
123         
124         //Scenario-3
125         clearTextByName("inputField5");
126         waitAndTypeByName("inputField6","a");
127         waitAndTypeByName("inputField8","a");
128         waitAndTypeByName("inputField5","");
129         String id = findElement(By.name("inputField8")).getAttribute("id");
130         assertTrue(findElement(By.id(id)).getAttribute("class").contains("error"));
131         fireEvent("inputField5", "blur");
132         fireMouseOverEventByName("inputField8");
133         assertTextPresent(EXAMPLE2_VALIDATION_MESSAGE);
134         
135         //Scenario-4
136         waitAndTypeByName("inputField7","a");
137         waitAndTypeByName("inputField5","");
138         if (isElementPresentByXpath(EXAMPLE2_ERROR_XPATH)){
139             jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
140         }
141         
142         //Scenario-5
143         waitAndTypeByName("inputField5","a");
144         waitAndTypeByName("inputField8","a");
145         assertTrue(findElement(By.id(id)).getAttribute("class").contains("error"));
146         fireEvent("inputField8", "blur");
147         fireMouseOverEventByName("inputField8");
148         assertTextPresent(EXAMPLE2_VALIDATION_MESSAGE);
149     }
150 
151     protected void testValidationMustOccurConstraintsExample3() throws Exception {
152         waitAndClickByLinkText("Example 3");
153         
154         //Scenario-1
155         assertFocusTypeBlurError("inputField13","a");
156         fireMouseOverEventByName("inputField13");
157         assertTextPresent(EXAMPLE3_VALIDATION_MESSAGE);
158         
159         //Scenario-2
160         waitAndTypeByName("inputField9","a");
161         waitAndTypeByName("inputField13","");
162         if (isElementPresentByXpath(EXAMPLE3_ERROR_XPATH)) {
163             jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
164         }
165         clearTextByName("inputField9");
166         
167         //Scenario-3
168         waitAndTypeByName("inputField10","a");
169         waitAndTypeByName("inputField13","");
170         if (isElementPresentByXpath(EXAMPLE3_ERROR_XPATH)) {
171             jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
172         }
173         clearTextByName("inputField10");
174         
175         //Scenario-4
176         waitAndTypeByName("inputField11","a");
177         waitAndTypeByName("inputField12","a");
178         waitAndTypeByName("inputField13","");
179         if (isElementPresentByXpath(EXAMPLE3_ERROR_XPATH)) {
180             jiraAwareFail("Criteria Not Satisfied " + this.getClass().toString());
181         }
182     }
183     
184 
185     @Test
186     public void testValidationMustOccurConstraintsBookmark() throws Exception {
187         testValidationMustOccurConstraintsExample1();
188         testValidationMustOccurConstraintsExample2();
189         testValidationMustOccurConstraintsExample3();
190         passed();
191     }
192 
193     @Test
194     public void testValidationMustOccurConstraintsNav() throws Exception {
195         testValidationMustOccurConstraintsExample1();
196         testValidationMustOccurConstraintsExample2();
197         testValidationMustOccurConstraintsExample3();
198         passed();
199     }
200 }