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