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.SmokeTestBase;
20  import org.junit.Test;
21  
22  import java.util.Arrays;
23  import java.util.Collections;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class BreadcrumbSmokeTest extends SmokeTestBase {
29  
30      /**
31       * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page1";
34  
35      /**
36       * //div[@class='uif-breadcrumbSiblingContent']//div[@class='uif-inputField']//ul[@class='uif-optionList']
37       */
38      public static final String SECOND_BREADCRUMB_NAV_XPATH = "//div[@class='uif-breadcrumbSiblingContent']//div[@class='uif-inputField']//ul[@class='uif-optionList']";
39  
40      /**
41       * (//a[@class='uif-breadcrumbSiblingLink'])[2]
42       * Not final as it needs to be overwritten for the Demo Breadcrumbs smoke test
43       */
44      public static final String SECOND_DOWN_TRIANGLE_XPATH = "(//a[@class='uif-breadcrumbSiblingLink'])[2]";
45  
46      String[][] selectAsserts = {{"UifCompView", "Uif Components"}};
47  
48      int[] breadcrumbOrderIndexes = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1};
49  
50      @Override
51      protected String getBookmarkUrl() {
52          return BOOKMARK_URL;
53      }
54  
55      protected String getTriangleXpath() {
56          return SECOND_DOWN_TRIANGLE_XPATH;
57      }
58  
59      protected void navigate() throws Exception {
60          waitAndClickKRAD();
61          waitAndClickByXpath(KITCHEN_SINK_XPATH);
62          switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
63      }
64  
65      protected void testBreadcrumb(int pageNumber) throws Exception {
66          // <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">
67          //         Input Fields and Controls
68          // </a></li>
69          // <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">
70          //         Other Fields
71          // </a></li>
72          // etc.
73          SeleneseTestBase.assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
74          // The second ▼
75          waitAndClickByXpath(getTriangleXpath());
76          Thread.sleep(100);
77          SeleneseTestBase.assertTrue(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
78          waitAndClickByXpath(getTriangleXpath());
79          SeleneseTestBase.assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
80          waitAndClickByXpath(getTriangleXpath());
81  
82          // The Second selection of the second ▼
83          // you can't just click by link text as the same clickable text is on the left navigation.
84          waitAndClickByXpath(SECOND_BREADCRUMB_NAV_XPATH +"/li[" + pageNumber + "]/a");
85          waitForElementPresentById("TopLink" + pageNumber); // bottom jump to top link
86          driver.getCurrentUrl().contains("pageId=UifCompView-Page" + pageNumber);
87      }
88  
89      protected void testBreadcrumbs() throws Exception {
90          for (int i = 0, s = breadcrumbOrderIndexes.length; i < s; i++) {
91              testBreadcrumb(breadcrumbOrderIndexes[i]);
92          }
93      }
94  
95      protected void testBreadcrumbsShuffled() throws Exception {
96          int[] copiedBreadcrumbOrderIndex = Arrays.copyOf(breadcrumbOrderIndexes, breadcrumbOrderIndexes.length);
97  
98          Collections.shuffle(Arrays.asList(copiedBreadcrumbOrderIndex));
99          for (int i = 0, s = copiedBreadcrumbOrderIndex.length; i < s; i++) {
100             testBreadcrumb(copiedBreadcrumbOrderIndex[i]);
101         }
102     }
103 
104     @Test
105     public void testBreadcrumbBookmark() throws Exception {
106         testBreadcrumbs();
107         passed();
108     }
109 
110     @Test
111     public void testBreadcrumbShuffledBookmark() throws Exception {
112         testBreadcrumbsShuffled();
113         passed();
114     }
115 
116     @Test
117     public void testBreadcrumbNav() throws Exception {
118         testBreadcrumbs();
119         passed();
120     }
121 
122     @Test
123     public void testBreadcrumbShuffledNav() throws Exception {
124         testBreadcrumbsShuffled();
125         passed();
126     }
127 }