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.demo.uif.library; 017 018 import edu.samplu.common.SmokeTestBase; 019 import org.kuali.rice.krad.uif.UifConstants; 020 import org.openqa.selenium.By; 021 import org.openqa.selenium.WebElement; 022 023 /** 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 */ 026 public abstract class DemoLibraryBase extends SmokeTestBase { 027 028 /** 029 * Automatically selects the library link and then navigate to the appropriate demo in the category 030 * specified 031 * 032 * @param libraryMenuCategoryName the category to select in the navigation accordion by name (text) 033 * @param demoItemName the demo link by name (text) 034 * @throws Exception 035 */ 036 public void navigateToLibraryDemo(String libraryMenuCategoryName, String demoItemName) throws Exception { 037 selectTopFrame(); 038 waitAndClickById("Demo-LibraryLink", ""); 039 waitAndClickByLinkText(libraryMenuCategoryName); 040 waitAndClickByLinkText(demoItemName); 041 } 042 043 /** 044 * Automatically selects and returns the appropriate example div by the id specified, works with demos 045 * that use either the tab navigation or dropdown navigation for their example navigation; 046 * if the example by id is already selected, this method still verifies that the group is visible and does not fail 047 * 048 * @param exampleId the id of the example 049 * @return the WebElement representing the example group 050 * @throws Exception 051 */ 052 public WebElement navigateToExample(String exampleId) throws Exception { 053 waitForElementPresentByClassName("demo-contactInfo"); // wait for page to load 054 WebElement exampleTab; 055 String tabId = "#" + exampleId + UifConstants.IdSuffixes.TAB; 056 057 if(isElementPresentById("ComponentLibrary-TabGroup_tabList") 058 && isElementPresentByDataAttributeValue(UifConstants.DataAttributes.TAB_FOR, exampleId)){ 059 WebElement menuItem = getElementByDataAttributeValue(UifConstants.DataAttributes.TAB_FOR, exampleId); 060 menuItem.findElement(By.cssSelector("a")).click(); 061 062 waitForElementPresent(tabId); 063 waitForElementVisible(tabId, ""); 064 } else if(isElementPresent(By.cssSelector("#Demo-LargeExampleDropdown_control"))){ 065 selectOption(By.cssSelector("#Demo-LargeExampleDropdown_control"), exampleId); 066 waitForElementPresent(tabId); 067 waitForElementVisible(tabId, ""); 068 driver.findElement(By.cssSelector(tabId)); 069 } else { 070 return null; // don't fail to avoid exception during setUp which results in failure not being recorded. 071 } 072 exampleTab = driver.findElement(By.cssSelector(tabId)); 073 return exampleTab; 074 } 075 }