View Javadoc
1   /**
2    * Copyright 2005-2014 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.widgets;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.demo.uif.library.DemoLibraryBase;
20  import org.kuali.rice.testtools.selenium.WebDriverUtils;
21  import org.openqa.selenium.By;
22  import org.openqa.selenium.WebElement;
23  
24  import java.util.List;
25  
26  /**
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class DemoWidgetsBreadcrumbsAft extends DemoLibraryBase {
30  
31  	  /**
32       * /kr-krad/kradsampleapp?viewId=Demo-BreadcrumbsView&methodToCall=start
33       */
34      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-BreadcrumbsView&methodToCall=start";
35  
36      /**
37       * inputField9
38       */
39      public static final String FIELD_TO_CHECK = "inputField9";
40  
41      /**
42       * Kuali
43       */
44      public static final String START_PAGE_TITLE = "Kuali";
45  
46      /**
47       * Kuali :: View Title
48       */
49      public static final String TARGET_PAGE_TITLE = "Kuali :: View Title";
50  
51      /**
52       * /kr-krad/kradsampleapp?viewId=Demo-Breadcrumbs-View
53       */
54      public static final String TARGET_URL_CHECK = "/kr-krad/kradsampleapp?viewId=Demo-Breadcrumbs-View";
55  
56      @Override
57      protected String getBookmarkUrl() {
58          return BOOKMARK_URL;
59      }
60  
61      @Override
62      protected void navigate() throws Exception {
63          navigateToLibraryDemo("Widgets", "Breadcrumbs");
64      }
65  
66      protected void testWidgetsBreadcrumbDefault() throws Exception {
67          waitAndClickByLinkText("Default");
68          waitAndClickByLinkText("Default Breadcrumbs");
69          assertNewWindow("1", "Default");
70      }
71  
72      protected void testWidgetsBreadcrumbParentLocation() throws Exception {
73          waitAndClickByLinkText("ParentLocation");
74          waitAndClickByLinkText("Home ParentLocation");
75          assertNewWindow("2", "ParentLocation");
76      }
77  
78      protected void testWidgetsBreadcrumbParentLocationChain() throws Exception {
79          waitAndClickByLinkText("ParentLocation Chain");
80          waitAndClickByLinkText("ParentLocation Chain/Trail");
81          assertNewWindow("3", "ParentLocation Chain");
82      }
83  
84      protected void testWidgetsBreadcrumbParentLocationPage() throws Exception {
85          waitAndClickByLinkText("ParentLocation Page");
86          waitAndClickByLinkText("ParentLocation View and Page");
87          assertNewWindow("4", "ParentLocation Page");
88      }
89  
90      protected void testWidgetsBreadcrumbPreViewAndPrePage() throws Exception {
91          waitAndClickByLinkText("preView and prePage");
92          waitAndClickByLinkText("preView and prePage breadcrumbs");
93          waitForPageToLoad();
94          switchToWindow(TARGET_PAGE_TITLE);
95          assertTrue("preView and prePage", driver.getCurrentUrl().contains(TARGET_URL_CHECK + "5"));
96          assertElementPresentByName(FIELD_TO_CHECK);
97          driver.close();
98          switchToWindow(START_PAGE_TITLE);
99      }
100 
101     protected void testWidgetsBreadcrumbBreadcrumbLabel() throws Exception {
102         waitAndClickByLinkText("Breadcrumb Label");
103         waitAndClickByLinkText("Override Breadcrumb Label");
104         assertNewWindow("6", "Breadcrumb Label");
105     }
106 
107     protected void testWidgetsBreadcrumbHomewardPath() throws Exception {
108         waitAndClickByLinkText("Homeward Path");
109         waitAndClickByLinkText("Homeward Path Breadcrumbs");
110         assertNewWindow("7", "Homeward Path");
111     }
112 
113     protected void testWidgetsBreadcrumbPathBased() throws Exception {
114         waitAndClickByLinkText("Path-based");
115         waitAndClickByLinkText("Path-based Breadcrumbs");
116         waitForPageToLoad();
117         switchToWindow(TARGET_PAGE_TITLE);
118         assertTrue("Path-based", driver.getCurrentUrl().contains(TARGET_URL_CHECK + "8"));
119         assertBreadcrumb(3);
120         waitAndClickByLinkText("Click me to continue chaining path-based breadcrumbs", "first click");
121         assertBreadcrumb(4);
122         waitAndClickByLinkText("Click me to continue chaining path-based breadcrumbs", "second click");
123         assertBreadcrumb(5);
124         driver.close();
125         switchToWindow(START_PAGE_TITLE);
126     }
127 
128     protected void assertBreadcrumb(int depth) throws Exception {
129         WebElement element = findElement(By.xpath("//ol[@role='navigation']"));
130         List<WebElement> elements = element.findElements(By.xpath("li"));
131         assertEquals(depth, elements.size());
132         assertTrue(elements.get(0).getText().contains("Home"));
133 
134         for (int i = 1; i < elements.size() - 1; i++) {
135             assertTrue(elements.get(i).getText().contains("View Title"));
136         }
137 
138         assertTrue(elements.get(elements.size() - 1).getText().contains("Page 1 Title"));
139     }
140 
141     protected void testWidgetsBreadcrumbOverrides() throws Exception {
142         waitAndClickByLinkText("Overrides");
143         waitAndClickByLinkText("Breadcrumb Overrides");
144         assertNewWindow("9", "Demo Page", "Demo Page", "Overrides");
145     }
146 
147     protected void testWidgetsBreadcrumbSiblingBreadcrumbs() throws Exception {
148         waitAndClickByLinkText("Sibling Breadcrumbs");
149         waitAndClickByXpath("//section[@id='Demo-Breadcrumbs-Example10']/a[contains(text(),'Sibling Breadcrumbs')]");
150         assertNewWindow("10", "Sibling Breadcrumbs");
151     }
152 
153     private void assertNewWindow(String urlNumber, String message) throws InterruptedException {
154         assertNewWindow(urlNumber, "Page 1 Title", "Page 2 Title", message);
155     }
156 
157     private void assertNewWindow(String urlNumber, String titleOne, String titleTwo, String message) throws InterruptedException {
158         Thread.sleep(WebDriverUtils.configuredImplicityWait() * 2000);
159         switchToWindow(TARGET_PAGE_TITLE);
160         assertTrue(message, driver.getCurrentUrl().contains(TARGET_URL_CHECK + urlNumber));
161         assertElementPresentByName(FIELD_TO_CHECK);
162         WebElement element = findElement(By.xpath("//span[@data-role='breadcrumb']"));
163         assertTrue(element.getText().contains(titleOne));
164         waitAndClickByLinkText("Page 2");
165         element = findElement(By.xpath("//span[@data-role='breadcrumb']"));
166         int secondsToWait = WebDriverUtils.configuredImplicityWait() * 3000;
167         while (!titleTwo.equals(element.getText().trim()) && secondsToWait > 0) {
168             Thread.sleep(4000);
169             secondsToWait -= 1000;
170             element = findElement(By.xpath("//span[@data-role='breadcrumb']"));
171         }
172         assertEquals(titleTwo, element.getText().trim());
173         driver.close();
174         switchToWindow(START_PAGE_TITLE);
175     }
176 
177     private void testAllBreadcrumb() throws Exception {
178         testWidgetsBreadcrumbSiblingBreadcrumbs();
179         testWidgetsBreadcrumbDefault();
180         testWidgetsBreadcrumbParentLocation();
181         testWidgetsBreadcrumbParentLocationChain();
182         testWidgetsBreadcrumbParentLocationPage();
183         testWidgetsBreadcrumbPreViewAndPrePage();
184         testWidgetsBreadcrumbBreadcrumbLabel();
185         testWidgetsBreadcrumbHomewardPath();
186         testWidgetsBreadcrumbPathBased();
187         testWidgetsBreadcrumbOverrides();
188         driver.close();
189     }
190 
191     @Test
192     public void testWidgetsBreadcrumbBookmark() throws Exception {
193         testAllBreadcrumb();
194         passed();
195     }
196 
197     @Test
198     public void testWidgetsBreadcrumbNav() throws Exception {
199         testAllBreadcrumb();
200         passed();
201     }
202 }