001/*
002 * (C) Copyright 2017 Nuxeo (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 *     Kevin Leturc
018 */
019package org.nuxeo.functionaltests.contentView;
020
021import static org.junit.Assert.assertEquals;
022
023import org.nuxeo.functionaltests.AbstractTest;
024import org.nuxeo.functionaltests.Locator;
025import org.nuxeo.functionaltests.fragment.WebFragmentImpl;
026import org.nuxeo.functionaltests.pages.AbstractPage;
027import org.nuxeo.functionaltests.pages.DocumentBasePage;
028import org.openqa.selenium.Alert;
029import org.openqa.selenium.By;
030import org.openqa.selenium.WebDriver;
031import org.openqa.selenium.WebElement;
032
033/**
034 * @since 9.1
035 */
036public class ContentViewSelectionActions extends WebFragmentImpl {
037
038    public static final String DELETE = "Delete";
039
040    public ContentViewSelectionActions(WebDriver driver, WebElement element) {
041        super(driver, element);
042    }
043
044    public DocumentBasePage delete() {
045        return delete(DocumentBasePage.class);
046    }
047
048    public <T extends AbstractPage> T delete(Class<T> pageClassToProxy) {
049        clickOnActionByTitle(DELETE);
050        Alert alert = driver.switchTo().alert();
051        assertEquals("Delete selected document(s)?", alert.getText());
052        alert.accept();
053        return AbstractTest.asPage(pageClassToProxy);
054    }
055
056    public void clickOnActionByTitle(String title) {
057        Locator.waitUntilEnabledAndClick(getActionByTitle(title));
058    }
059
060    public <T extends AbstractPage> T clickOnActionByTitle(String title, Class<T> pageClassToProxy) {
061        clickOnActionByTitle(title);
062        return AbstractTest.asPage(pageClassToProxy);
063    }
064
065    public WebElement getActionByTitle(String title) {
066        return getElement().findElement(By.xpath("//input[@value=\"" + title + "\"]"));
067    }
068
069}