1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  
30  
31  public abstract class BreadcrumbSmokeTestBase extends WebDriverLegacyITBase {
32  
33      
34  
35  
36      public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=UifCompView&methodToCall=start&pageId=UifCompView-Page1";
37  
38      
39  
40  
41      public static final String NAVIGATE_TO_LABEL_XPATH = "//label[contains(text(), 'Navigate to')]";
42  
43      
44  
45  
46      public static final String SECOND_BREADCRUMB_NAV_XPATH = "//*[@class='uif-optionList']";
47  
48      
49  
50  
51      public static final String SECOND_DOWN_TRIANGLE_XPATH = "(//a[@class='uif-breadcrumbSiblingLink'])";
52  
53      
54  
55  
56  
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         
124         
125         
126         
127         
128         
129         
130         SeleneseTestBase.assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
131         
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         
139         
140         waitAndClickByXpath(SECOND_BREADCRUMB_NAV_XPATH +"/li[" + pageNumber + "]/a");
141         waitForElementPresentById("TopLink" + pageNumber); 
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         
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         
184         waitForElementPresentById("Uif-BreadcrumbWrapper");
185 
186         
187         waitForElementPresentById("u12");
188         SeleneseTestBase.assertEquals("Input Fields and Controls", getTextById("u12"));
189 
190         
191         
192         
193         SeleneseTestBase.assertFalse(isVisibleByXpath(NAVIGATE_TO_LABEL_XPATH));
194         
195         waitAndClickByLinkText("▼");
196         SeleneseTestBase.assertTrue(isVisibleByXpath(NAVIGATE_TO_LABEL_XPATH));
197         SeleneseTestBase.assertEquals("Navigate to:",getTextByXpath(NAVIGATE_TO_LABEL_XPATH));
198         
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 }