View Javadoc

1   /*
2    * Copyright 2005-2013 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 edu.samplu.krad.compview;
17  
18  import com.thoughtworks.selenium.SeleneseTestBase;
19  import edu.samplu.common.Failable;
20  import edu.samplu.common.ITUtil;
21  import edu.samplu.common.WebDriverLegacyITBase;
22  import org.openqa.selenium.By;
23  
24  import java.util.Arrays;
25  import java.util.Collections;
26  import java.util.List;
27  
28  /**
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public abstract class BreadcrumbSmokeTestBase extends WebDriverLegacyITBase {
32  
33      /**
34       * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3
35       */
36      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page1";
37  
38      /**
39       * //label[contains(text(), 'Navigate to')]
40       */
41      public static final String NAVIGATE_TO_LABEL_XPATH = "//label[contains(text(), 'Navigate to')]";
42  
43      /**
44       * //*[@class='uif-optionList']
45       */
46      public static final String SECOND_BREADCRUMB_NAV_XPATH = "//*[@class='uif-optionList']";
47  
48      /**
49       * //*[@id='Uif-BreadcrumbWrapper']/ol/li[2]/a
50       */
51      public static final String SECOND_DOWN_TRIANGLE_XPATH = "(//a[@class='uif-breadcrumbSiblingLink'])[2]";
52  
53      /**
54       * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}.  Bookmark Tests should override and return {@link BreadcrumbSmokeTestBase#BOOKMARK_URL}
55       * {@inheritDoc}
56       * @return
57       */
58  
59      String[][] selectAsserts = {{"UifCompView", "Uif Components"},
60              {"ConfigurationTestView", "Configuration Test View"},
61              {"RichMessagesView", "Rich Messages"},
62              {"Demo-ReadOnlyTestView", "ReadOnly Test"},
63              {"ClientDisableView", "Client-side Disable"}};
64  
65      int[] breadcrumbOrderIndexes = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1};
66  
67      @Override
68      public String getTestUrl() {
69          return ITUtil.PORTAL;
70      }
71  
72      protected void navigation() throws Exception {
73          waitAndClickKRAD();
74          waitAndClickByXpath(KITCHEN_SINK_XPATH);
75          switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
76      }
77  
78      protected void testBreadcrumbBookmark(Failable failable) throws Exception {
79          testBreadcrumbs();
80          passed();
81      }
82  
83      protected void testBreadcrumbShuffledBookmark(Failable failable) throws Exception {
84          testBreadcrumbsShuffled();
85          passed();
86      }
87  
88      protected void testBreadcrumbShuffledNav(Failable failable) throws Exception {
89          navigation();
90          testBreadcrumbsShuffled();
91          passed();
92      }
93  
94      protected void testBreadcrumbNav(Failable failable) throws Exception {
95          navigation();
96          testBreadcrumbs();
97          passed();
98      }
99  
100     protected void testBreadcrumbNavigateToBookmark(Failable failable) throws Exception {
101         testBreadcrumbNavigateTo();
102         passed();
103     }
104 
105     protected void testBreadcrumbNavigateToShuffledBookmark(Failable failable) throws Exception {
106         testBreadcrumbNavigateToShuffled();
107         passed();
108     }
109 
110     protected void testBreadcrumbNavigateToNav(Failable failable) throws Exception {
111         navigation();
112         testBreadcrumbNavigateTo();
113         passed();
114     }
115 
116     protected void testBreadcrumbNavigateToShuffledNav(Failable failable) throws Exception {
117         navigation();
118         testBreadcrumbNavigateToShuffled();
119         passed();
120     }
121 
122     protected void testBreadcrumb(int pageNumber) throws Exception {
123         // <ul id="u13_control" class="uif-optionList" data-control_for="u13" tabindex="0"><li class="uif-optionList-item uif-optionList-selectedItem"><a href="http://env1.rice.kuali.org/kr-krad/uicomponents?methodToCall=start&pageId=UifCompView-Page1&viewId=UifCompView" data-key="UifCompView-Page1">
124         //         Input Fields and Controls
125         // </a></li>
126         // <li class="uif-optionList-item"><a href="http://env1.rice.kuali.org/kr-krad/uicomponents?methodToCall=start&pageId=UifCompView-Page2&viewId=UifCompView" data-key="UifCompView-Page2">
127         //         Other Fields
128         // </a></li>
129         // etc.
130         SeleneseTestBase.assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
131         // The second ▼
132         waitAndClickByXpath(SECOND_DOWN_TRIANGLE_XPATH);
133         SeleneseTestBase.assertTrue(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
134         waitAndClickByXpath(SECOND_DOWN_TRIANGLE_XPATH);
135         SeleneseTestBase.assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
136         waitAndClickByXpath(SECOND_DOWN_TRIANGLE_XPATH);
137 
138         // The Second selection of the second ▼
139         // you can't just click by link text as the same clickable text is on the left navigation.
140         waitAndClickByXpath(SECOND_BREADCRUMB_NAV_XPATH +"/li[" + pageNumber + "]/a");
141         waitForElementPresentById("TopLink" + pageNumber); // bottom jump to top link
142         driver.getCurrentUrl().contains("pageId=UifCompView-Page" + pageNumber);
143     }
144 
145     protected void testBreadcrumbs() throws Exception {
146         for (int i = 0, s = breadcrumbOrderIndexes.length; i < s; i++) {
147             testBreadcrumb(breadcrumbOrderIndexes[i]);
148         }
149     }
150 
151     protected void testBreadcrumbsShuffled() throws Exception {
152         int[] copiedBreadcrumbOrderIndex = Arrays.copyOf(breadcrumbOrderIndexes, breadcrumbOrderIndexes.length);
153 
154         Collections.shuffle(Arrays.asList(copiedBreadcrumbOrderIndex));
155         for (int i = 0, s = copiedBreadcrumbOrderIndex.length; i < s; i++) {
156             testBreadcrumb(copiedBreadcrumbOrderIndex[i]);
157         }
158     }
159 
160     protected void testBreadcrumbNavigateToShuffled() throws Exception {
161         testBreadcrumbNavigateToSetup();
162 
163         Collections.shuffle(Arrays.asList(selectAsserts));
164         for (int i = 0, s = selectAsserts.length; i < s; i++) {
165             selectAndAssertNavigationTo(selectAsserts[i]);
166         }
167     }
168 
169     protected void testBreadcrumbNavigateTo() throws Exception {
170         testBreadcrumbNavigateToSetup();
171 
172         // Not in a loop here so failures are easier to track
173         selectAndAssertNavigationTo(selectAsserts[1][0], selectAsserts[1][1]);
174         selectAndAssertNavigationTo(selectAsserts[2][0], selectAsserts[2][1]);
175         selectAndAssertNavigationTo(selectAsserts[3][0], selectAsserts[3][1]);
176         selectAndAssertNavigationTo(selectAsserts[4][0], selectAsserts[4][1]);
177         selectAndAssertNavigationTo(selectAsserts[0][0], selectAsserts[0][1]);
178     }
179 
180     protected void testBreadcrumbNavigateToSetup() throws InterruptedException {
181         selectTopFrame();
182 
183         // div id="Uif-BreadcrumbWrapper" class="uif-sticky" data-sticky="true" style="position:fixed; left: 0; top: 39.55000305175781px;">
184         waitForElementPresentById("Uif-BreadcrumbWrapper");
185 
186         // <span data-role="breadcrumb" id="u12">Input Fields and Controls</span>
187         waitForElementPresentById("u12");
188         SeleneseTestBase.assertEquals("Input Fields and Controls", getTextById("u12"));
189 
190         // <label id="u6610_label" for="u6610_control" data-label_for="u6610">
191         //        Navigate to:
192         // </label>
193         SeleneseTestBase.assertFalse(isVisibleByXpath(NAVIGATE_TO_LABEL_XPATH));
194         // the first ▼
195         waitAndClickByLinkText("▼");
196         SeleneseTestBase.assertTrue(isVisibleByXpath(NAVIGATE_TO_LABEL_XPATH));
197         SeleneseTestBase.assertEquals("Navigate to:",getTextByXpath(NAVIGATE_TO_LABEL_XPATH));
198         // the first ▼
199         waitAndClickByLinkText("▼");
200         SeleneseTestBase.assertFalse(isVisibleByXpath(NAVIGATE_TO_LABEL_XPATH));
201     }
202 
203     protected void selectAndAssertNavigationTo(String[] selectAssert) throws InterruptedException {
204         selectAndAssertNavigationTo(selectAssert[0], selectAssert[1]);
205     }
206 
207     protected void selectAndAssertNavigationTo(String selectText, String assertText) throws InterruptedException {
208         if (isTextPresent("KRAD Labs")) {
209             this.fail("Should not be on KRAD Labs page, did back after Breadcrumb Navigate To work?");
210         }
211         waitAndClickByLinkText("▼");
212         selectOption(By.xpath("//select[@name='viewId']"), selectText);
213         checkForIncidentReport();
214         waitForElementPresentByXpath("//span[@class='uif-headerText-span']");
215         checkForIncidentReport();
216         SeleneseTestBase.assertEquals(assertText, getText(By.xpath("//span[@class='uif-headerText-span']")));
217         back();
218     }
219 }