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;
17  
18  import org.kuali.rice.krad.uif.UifConstants;
19  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
20  import org.kuali.rice.testtools.selenium.WebDriverUtils;
21  import org.openqa.selenium.By;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public abstract class DemoLibraryBase extends WebDriverLegacyITBase {
28  
29      /**
30       * Automatically selects the library link and then navigate to the appropriate demo in the category
31       * specified
32       *
33       * @param libraryMenuCategoryName the category to select in the navigation accordion by name (text)
34       * @param demoItemName the demo link by name (text)
35       * @throws Exception
36       */
37      public void navigateToLibraryDemo(String libraryMenuCategoryName, String demoItemName) throws Exception {
38          selectTopFrame();
39          jGrowl("Click Library Link.");
40          waitAndClickById("Demo-LibraryLink", "");
41          waitAndClickByLinkText(libraryMenuCategoryName);
42          waitAndClickByLinkText(demoItemName);
43      }
44  
45      /**
46       * Automatically selects and returns the appropriate example div by the id specified, works with demos
47       * that use either the tab navigation or dropdown navigation for their example navigation;
48       * if the example by id is already selected, this method still verifies that the group is visible and does not fail
49       *
50       * @param exampleId the id of the example
51       * @return the WebElement representing the example group
52       * @throws Exception
53       */
54      public WebElement navigateToExample(String exampleId) throws Exception {
55          waitForElementPresentByClassName("demo-contactInfo", WebDriverUtils.configuredImplicityWait() * 2000); // wait for page to load
56          WebElement exampleTab;
57          String tabId = "#" + exampleId + UifConstants.IdSuffixes.TAB + "Panel"; // Why hasn't TAB been updated?
58  
59          if(isElementPresentById("ComponentLibrary-TabGroup_tabList")
60                  && isElementPresentByDataAttributeValue(UifConstants.DataAttributes.TAB_FOR, exampleId)){
61              getElementByAttributeValue("href", tabId).click();
62  
63              waitForElementPresent(tabId);
64              waitForElementVisible(tabId, "");
65          } else if(isElementPresent(By.cssSelector("#Demo-LargeExampleDropdown_control"))){
66              selectOption(By.cssSelector("#Demo-LargeExampleDropdown_control"), exampleId);
67              waitForElementPresent(tabId);
68              waitForElementVisible(tabId, "");
69              driver.findElement(By.cssSelector(tabId));
70          } else {
71              return null; // don't fail to avoid exception during setUp which results in failure not being recorded.
72          }
73          exampleTab = driver.findElement(By.cssSelector(tabId));
74          return exampleTab;
75      }
76  }