View Javadoc
1   /**
2    * Copyright 2005-2015 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.LibraryBase;
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 LibraryWidgetsBreadcrumbsAft extends LibraryBase {
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         waitForPageToLoad();
105         switchToWindow(TARGET_PAGE_TITLE);
106         assertTrue("Breadcrumb label", driver.getCurrentUrl().contains(TARGET_URL_CHECK + "6"));
107         assertTextPresent("View (avalue1)");
108         driver.close();
109         switchToWindow(START_PAGE_TITLE);
110     }
111 
112     protected void testWidgetsBreadcrumbHomewardPath() throws Exception {
113         waitAndClickByLinkText("Homeward Path");
114         waitAndClickByLinkText("Homeward Path Breadcrumbs");
115         assertNewWindow("7", "Homeward Path");
116     }
117 
118     protected void testWidgetsBreadcrumbPathBased() throws Exception {
119         waitAndClickByLinkText("Path-based");
120         waitAndClickByLinkText("Path-based Breadcrumbs");
121         waitForPageToLoad();
122         switchToWindow(TARGET_PAGE_TITLE);
123         assertTrue("Path-based", driver.getCurrentUrl().contains(TARGET_URL_CHECK + "8"));
124         assertBreadcrumb(3);
125         waitAndClickByLinkText("Click me to continue chaining path-based breadcrumbs", "first click");
126         assertBreadcrumb(4);
127         waitAndClickByLinkText("Click me to continue chaining path-based breadcrumbs", "second click");
128         assertBreadcrumb(5);
129         driver.close();
130         switchToWindow(START_PAGE_TITLE);
131     }
132 
133     protected void assertBreadcrumb(int depth) throws Exception {
134         WebElement element = findElement(By.xpath("//ol[@role='navigation']"));
135         List<WebElement> elements = element.findElements(By.xpath("li"));
136         assertEquals(depth, elements.size());
137         assertTrue(elements.get(0).getText().contains("Home"));
138 
139         for (int i = 1; i < elements.size() - 1; i++) {
140             assertTrue(elements.get(i).getText().contains("View Title"));
141         }
142 
143         assertTrue(elements.get(elements.size() - 1).getText().contains("Page 1 Title"));
144     }
145 
146     protected void testWidgetsBreadcrumbOverrides() throws Exception {
147         waitAndClickByLinkText("Overrides");
148         waitAndClickByLinkText("Breadcrumb Overrides");
149         assertNewWindow("9", "Demo Page", "Demo Page", "Overrides");
150     }
151 
152     protected void testWidgetsBreadcrumbSiblingBreadcrumbs() throws Exception {
153         waitAndClickByLinkText("Sibling Breadcrumbs");
154         waitAndClickByXpath("//section[@id='Demo-Breadcrumbs-Example10']/a[contains(text(),'Sibling Breadcrumbs')]");
155         assertNewWindow("10", "Sibling Breadcrumbs");
156     }
157 
158     private void assertNewWindow(String urlNumber, String message) throws InterruptedException {
159         assertNewWindow(urlNumber, "Page 1 Title", "Page 2 Title", message);
160     }
161 
162     private void assertNewWindow(String urlNumber, String titleOne, String titleTwo, String message) throws InterruptedException {
163         Thread.sleep(WebDriverUtils.configuredImplicityWait() * 2000);
164         switchToWindow(TARGET_PAGE_TITLE);
165         assertTrue(message, driver.getCurrentUrl().contains(TARGET_URL_CHECK + urlNumber));
166         assertElementPresentByName(FIELD_TO_CHECK);
167         WebElement element = findElement(By.xpath("//span[@data-role='breadcrumb']"));
168         assertTrue(element.getText().contains(titleOne));
169         waitAndClickByLinkText("Page 2");
170         element = findElement(By.xpath("//span[@data-role='breadcrumb']"));
171         int millisecondsToWait = WebDriverUtils.configuredImplicityWait() * 3000;
172         while (!titleTwo.equals(element.getText().trim()) && millisecondsToWait > 0) {
173             Thread.sleep(4000);
174             millisecondsToWait -= 1000;
175             element = findElement(By.xpath("//span[@data-role='breadcrumb']"));
176         }
177         assertEquals(titleTwo, element.getText().trim());
178         driver.close();
179         switchToWindow(START_PAGE_TITLE);
180     }
181 
182     private void testAllBreadcrumb() throws Exception {
183         testWidgetsBreadcrumbSiblingBreadcrumbs();
184         testWidgetsBreadcrumbDefault();
185         testWidgetsBreadcrumbParentLocation();
186         testWidgetsBreadcrumbParentLocationChain();
187         testWidgetsBreadcrumbParentLocationPage();
188         testWidgetsBreadcrumbPreViewAndPrePage();
189         testWidgetsBreadcrumbBreadcrumbLabel();
190         testWidgetsBreadcrumbHomewardPath();
191         testWidgetsBreadcrumbPathBased();
192         testWidgetsBreadcrumbOverrides();
193         passed();
194         driver.close();
195     }
196 
197     @Test
198     public void testWidgetsBreadcrumbBookmark() throws Exception {
199         testAllBreadcrumb();
200         passed();
201     }
202 
203     @Test
204     public void testWidgetsBreadcrumbNav() throws Exception {
205         testAllBreadcrumb();
206         passed();
207     }
208 }