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.controls;
17  
18  import org.junit.Test;
19  
20  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class LibraryControlCheckboxGroupAft extends WebDriverLegacyITBase {
26  
27      /**
28       * /kr-krad/kradsampleapp?viewId=Demo-CheckboxGroupControlView&methodToCall=start
29       */
30      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-CheckboxGroupControlView&methodToCall=start";
31  
32      @Override
33      protected String getBookmarkUrl() {
34          return BOOKMARK_URL;
35      }
36  
37      @Override
38      protected void navigate() throws Exception {
39          waitAndClickLibraryLink();
40          waitAndClickByLinkText("Controls");
41          waitAndClickByLinkText("Checkbox Group");
42      }
43  
44      protected void testLibraryControlCheckboxGroupOptionsFinder() throws Exception {
45          waitAndClickByLinkText("optionsFinder");
46          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField1' and @value='1']");
47          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField1' and @value='5']");
48      }
49      
50      protected void testLibraryControlCheckboxGroupKeyValuePairs() throws Exception {
51          waitAndClickByLinkText("Key Value Pairs");
52          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField2' and @value='1']");
53          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField2' and @value='3']");
54      }
55      
56      protected void testLibraryControlCheckboxGroupHorizontal() throws Exception {
57          waitAndClickByLinkText("Horizontal");
58          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField3' and @value='1']");
59          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField3' and @value='2']");
60      }
61      
62      protected void testLibraryControlCheckboxGroupDelimiter() throws Exception {
63          waitAndClickByLinkText("Delimiter");
64          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField4' and @value='1']");
65          assertTextPresent("\n|");
66          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField4' and @value='2']");
67      }
68  
69      protected void testLibraryControlCheckboxGroupDirtyValidation() throws Exception {
70          // If checkboxes are selected then the "Form has unsaved data" message should appear when the user attempts
71          // to leave the page.
72          waitAndClickByLinkText("optionsFinder");
73          checkByName("checkboxesField1");
74          waitAndClickByLinkText("File");
75          Thread.sleep(3000);
76          if(isAlertPresent())    {
77              alertAccept();
78          } else {
79              fail("An alert should have popped up to warn the user about unsaved data.");
80          }
81  
82          waitForTextPresent("File Control");
83          waitAndClickByLinkText("Checkbox Group");
84          waitAndClickByLinkText("optionsFinder");
85          waitForElementPresentByXpath("//input[@type='checkbox' and @name='checkboxesField1' and @value='1']");
86          waitAndClickByLinkText("File");
87          waitForTextPresent("File Control");
88          if(isAlertPresent())    {
89              fail("No data was changed so there should be no alert.");
90          }
91      }
92  
93      protected boolean isAlertPresent() {
94          try {
95              driver.switchTo().alert();
96              return true;
97          }   // try
98          catch (Exception Ex) {
99              return false;
100         }   // catch
101     }
102 
103     @Test
104     public void testControlCheckboxGroupBookmark() throws Exception {
105         testLibraryControlCheckboxGroupOptionsFinder();
106         testLibraryControlCheckboxGroupKeyValuePairs();
107         testLibraryControlCheckboxGroupHorizontal();
108         testLibraryControlCheckboxGroupDelimiter();
109         testLibraryControlCheckboxGroupDirtyValidation();
110         passed();
111     }
112 
113     @Test
114     public void testControlCheckboxGroupNav() throws Exception {
115         testLibraryControlCheckboxGroupOptionsFinder();
116         testLibraryControlCheckboxGroupKeyValuePairs();
117         testLibraryControlCheckboxGroupHorizontal();
118         testLibraryControlCheckboxGroupDelimiter();
119         testLibraryControlCheckboxGroupDirtyValidation();
120         passed();
121     }  
122 }