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.AjaxRequestManager;
022import org.nuxeo.functionaltests.Locator;
023import org.nuxeo.functionaltests.pages.AbstractPage;
024import org.openqa.selenium.By;
025import org.openqa.selenium.StaleElementReferenceException;
026import org.openqa.selenium.WebDriver;
027import org.openqa.selenium.WebElement;
028import org.openqa.selenium.support.FindBy;
029
030import com.google.common.base.Function;
031
032/**
033 * The document contextual actions
034 */
035public class ContextualActions extends AbstractPage {
036
037    @FindBy(xpath = "//img[@alt=\"Lock\"]")
038    public WebElement lockButton;
039
040    @FindBy(xpath = "//img[@alt=\"Follow this Document\"]")
041    public WebElement followButton;
042
043    @FindBy(xpath = "//img[@alt=\"Add to Worklist\"]")
044    public WebElement addToWorklistButton;
045
046    @FindBy(id = "nxw_permalinkAction_form:nxw_documentActionsUpperButtons_permalinkAction_subview:nxw_documentActionsUpperButtons_permalinkAction_link")
047    public WebElement permaButton;
048
049    public String permaBoxFocusName = "permalinkFocus";
050
051    @FindBy(xpath = "//img[@alt=\"Export\"]")
052    public WebElement exportButton;
053
054    @FindBy(xpath = "//img[@alt=\"Add to Favorites\"]")
055    public WebElement favoritesButton;
056
057    public String xmlExportTitle = "XML Export";
058
059    public ContextualActions(WebDriver driver) {
060        super(driver);
061    }
062
063    public ContextualActions clickOnButton(WebElement button) {
064        button.click();
065        return asPage(ContextualActions.class);
066    }
067
068    /**
069     * Clicks on "More" button, making sure we wait for content to be shown.
070     *
071     * @since 8.1
072     */
073    public ContextualActions openMore() {
074        String xpath = "//div[@id=\"nxw_documentActionsUpperButtons_panel\"]/div/ul/li";
075        driver.findElement(By.xpath(xpath)).click();
076        Locator.waitUntilGivenFunctionIgnoring(new Function<WebDriver, Boolean>() {
077            @Override
078            public Boolean apply(WebDriver input) {
079                return driver.findElement(By.xpath(xpath + "/ul")).isDisplayed();
080            }
081        }, StaleElementReferenceException.class);
082        return asPage(ContextualActions.class);
083    }
084
085    /**
086     * Clicks on "More" button, making sure we wait for content to be shown.
087     *
088     * @since 8.1
089     */
090    public ContextualActions closeFancyPermalinBox() {
091        AjaxRequestManager arm = new AjaxRequestManager(driver);
092        arm.begin();
093        driver.findElement(By.id("fancybox-close")).click();
094        arm.end();
095        return asPage(ContextualActions.class);
096    }
097
098}