001 /*
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.krad.compview;
017
018 import com.thoughtworks.selenium.SeleneseTestBase;
019 import edu.samplu.common.Failable;
020 import edu.samplu.common.ITUtil;
021 import edu.samplu.common.WebDriverLegacyITBase;
022 import org.openqa.selenium.By;
023
024 import java.util.Arrays;
025 import java.util.Collections;
026 import java.util.List;
027
028 /**
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031 public abstract class BreadcrumbSmokeTestBase extends WebDriverLegacyITBase {
032
033 /**
034 * /kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page3
035 */
036 public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page1";
037
038 /**
039 * //label[contains(text(), 'Navigate to')]
040 */
041 public static final String NAVIGATE_TO_LABEL_XPATH = "//label[contains(text(), 'Navigate to')]";
042
043 /**
044 * //*[@class='uif-optionList']
045 */
046 public static final String SECOND_BREADCRUMB_NAV_XPATH = "//*[@class='uif-optionList']";
047
048 /**
049 * //*[@id='Uif-BreadcrumbWrapper']/ol/li[2]/a
050 */
051 public static final String SECOND_DOWN_TRIANGLE_XPATH = "(//a[@class='uif-breadcrumbSiblingLink'])[2]";
052
053 /**
054 * Nav tests start at {@link edu.samplu.common.ITUtil#PORTAL}. Bookmark Tests should override and return {@link BreadcrumbSmokeTestBase#BOOKMARK_URL}
055 * {@inheritDoc}
056 * @return
057 */
058
059 String[][] selectAsserts = {{"UifCompView", "Uif Components"},
060 {"ConfigurationTestView", "Configuration Test View"},
061 {"RichMessagesView", "Rich Messages"},
062 {"Demo-ReadOnlyTestView", "ReadOnly Test"},
063 {"ClientDisableView", "Client-side Disable"}};
064
065 int[] breadcrumbOrderIndexes = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1};
066
067 @Override
068 public String getTestUrl() {
069 return ITUtil.PORTAL;
070 }
071
072 protected void navigation() throws Exception {
073 waitAndClickKRAD();
074 waitAndClickByXpath(KITCHEN_SINK_XPATH);
075 switchToWindow(KUALI_UIF_COMPONENTS_WINDOW_XPATH);
076 }
077
078 protected void testBreadcrumbBookmark(Failable failable) throws Exception {
079 testBreadcrumbs();
080 passed();
081 }
082
083 protected void testBreadcrumbShuffledBookmark(Failable failable) throws Exception {
084 testBreadcrumbsShuffled();
085 passed();
086 }
087
088 protected void testBreadcrumbShuffledNav(Failable failable) throws Exception {
089 navigation();
090 testBreadcrumbsShuffled();
091 passed();
092 }
093
094 protected void testBreadcrumbNav(Failable failable) throws Exception {
095 navigation();
096 testBreadcrumbs();
097 passed();
098 }
099
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 }