001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.krad.demo.uif.library;
017
018import org.kuali.rice.krad.uif.UifConstants;
019import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
020import org.kuali.rice.testtools.selenium.WebDriverUtils;
021import org.openqa.selenium.By;
022import org.openqa.selenium.WebElement;
023
024/**
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public abstract class LibraryBase extends WebDriverLegacyITBase {
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        waitAndClickLibraryLink();
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 + "Panel"; // Why hasn't TAB been updated?
057
058        if(isElementPresentById("ComponentLibrary-TabGroup_tabList")
059                && isElementPresentByDataAttributeValue(UifConstants.DataAttributes.TAB_FOR, exampleId)){
060            getElementByAttributeValue("href", tabId).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}