001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 * Contributors:
017 *     <a href=mailto:vpasquier@nuxeo.com>Vladimir Pasquier</a>
018 */
019package org.nuxeo.functionaltests.pages.actions;
020
021import org.nuxeo.functionaltests.Locator;
022import org.nuxeo.functionaltests.pages.AbstractPage;
023import org.openqa.selenium.By;
024import org.openqa.selenium.StaleElementReferenceException;
025import org.openqa.selenium.WebDriver;
026import org.openqa.selenium.WebElement;
027import org.openqa.selenium.support.FindBy;
028
029import com.google.common.base.Function;
030
031/**
032 * The document contextual actions
033 */
034public class ContextualActions extends AbstractPage {
035
036    @FindBy(xpath = "//img[@alt=\"Lock\"]")
037    public WebElement lockButton;
038
039    @FindBy(xpath = "//img[@alt=\"Unlock\"]")
040    public WebElement unlockButton;
041
042    @FindBy(xpath = "//img[@alt=\"Follow this Document\"]")
043    public WebElement followButton;
044
045    @FindBy(xpath = "//img[@alt=\"Add to Worklist\"]")
046    public WebElement addToWorklistButton;
047
048    @FindBy(id = "nxw_permalinkAction_form:nxw_permalinkAction_link")
049    public WebElement permaButton;
050
051    public String permaBoxFocusName = "permalinkFocus";
052
053    @FindBy(xpath = "//img[@alt=\"Export\"]")
054    public WebElement exportButton;
055
056    @FindBy(xpath = "//img[@alt=\"Add to Favorites\"]")
057    public WebElement favoritesButton;
058
059    public String xmlExportTitle = "XML Export";
060
061    public ContextualActions(WebDriver driver) {
062        super(driver);
063    }
064
065    public ContextualActions clickOnButton(WebElement button) {
066        button.click();
067        return asPage(ContextualActions.class);
068    }
069
070    /**
071     * Clicks on "More" button, making sure we wait for content to be shown.
072     *
073     * @since 8.1
074     */
075    public ContextualActions openMore() {
076        String xpath = "//ul[@id=\"nxw_documentActionsUpperButtons_dropDownMenu\"]/li";
077        driver.findElement(By.xpath(xpath)).click();
078        Locator.waitUntilGivenFunctionIgnoring(new Function<WebDriver, Boolean>() {
079            @Override
080            public Boolean apply(WebDriver input) {
081                return driver.findElement(By.xpath(xpath + "/ul")).isDisplayed();
082            }
083        }, StaleElementReferenceException.class);
084        return asPage(ContextualActions.class);
085    }
086
087    /**
088     * Clicks on "More" button, making sure we wait for content to be shown.
089     *
090     * @since 8.1
091     */
092    public ContextualActions closeFancyPermalinBox() {
093        AbstractPage.closeFancyBox();
094        return asPage(ContextualActions.class);
095    }
096
097}