View Javadoc

1   /*
2    * Copyright 2006-2013 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  
17  package edu.samplu.krad.demo.uif.library;
18  
19  import com.thoughtworks.selenium.SeleneseTestBase;
20  import edu.samplu.common.WebDriverLegacyITBase;
21  import org.kuali.rice.krad.uif.UifConstants;
22  import org.openqa.selenium.By;
23  import org.openqa.selenium.WebElement;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public abstract class DemoLibraryITBase extends WebDriverLegacyITBase {
29  
30      /**
31       * Automatically selects the library link and then navigate to the appropriate demo in the category
32       * specified
33       *
34       * @param libraryMenuCategoryName the category to select in the navigation accordion by name (text)
35       * @param demoItemName the demo link by name (text)
36       * @throws Exception
37       */
38      public void navigateToLibraryDemo(String libraryMenuCategoryName, String demoItemName) throws Exception{
39          waitAndClickById("Demo-LibraryLink", "");
40          waitAndClickByLinkText(libraryMenuCategoryName);
41          waitAndClickByLinkText(demoItemName);
42      }
43  
44      /**
45       * Automatically selects and returns the appropriate example div by the id specified, works with demos
46       * that use either the tab navigation or dropdown navigation for their example navigation;
47       * if the example by id is already selected, this method still verifies that the group is visible and does not fail
48       *
49       * @param exampleId the id of the example
50       * @return the WebElement representing the example group
51       * @throws Exception
52       */
53      public WebElement navigateToExample(String exampleId) throws Exception{
54          WebElement exampleTab;
55          String tabId = "#" + exampleId + UifConstants.IdSuffixes.TAB;
56  
57          if(isVisibleById("ComponentLibrary-TabGroup_tabList")
58                  && isElementPresentByDataAttributeValue(UifConstants.DataAttributes.TAB_FOR, exampleId)){
59              WebElement menuItem = getElementByDataAttributeValue(UifConstants.DataAttributes.TAB_FOR, exampleId);
60              menuItem.findElement(By.cssSelector("a")).click();
61  
62              waitForElementPresent(tabId);
63              waitForElementVisible(tabId, "");
64          }
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          }
71          else{
72              SeleneseTestBase.fail(exampleId + " does not exist as an example for this demo");
73          }
74  
75          exampleTab = driver.findElement(By.cssSelector(tabId));
76          return exampleTab;
77      }
78  }