001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat
016 */
017
018package org.nuxeo.functionaltests.pages.admincenter;
019
020import org.nuxeo.functionaltests.pages.AbstractPage;
021import org.openqa.selenium.By;
022import org.openqa.selenium.WebDriver;
023import org.openqa.selenium.WebElement;
024
025public class PackageListingPage extends AbstractPage {
026
027    public PackageListingPage(WebDriver driver) {
028        super(driver);
029    }
030
031    public WebElement getPackageLink(String packageId) {
032        String xpath = "id('row_" + packageId + "')//a[contains(@class ,'button')]";
033        return findElementWithTimeout(By.xpath(xpath), 20 * 1000);
034    }
035
036    public WebElement getPackageDownloadLink(String packageId) {
037        WebElement link = getPackageLink(packageId);
038        if (link != null) {
039            if (link.getText().trim().toLowerCase().startsWith("download")) {
040                return link;
041            }
042        }
043        return null;
044    }
045
046    public WebElement getPackageInstallLink(String packageId) {
047        WebElement link = getPackageLink(packageId);
048        if (link != null) {
049            if (link.getText().trim().toLowerCase().startsWith("install")) {
050                return link;
051            }
052        }
053        return null;
054    }
055
056    public WebElement download(String packageId) {
057        System.out.println(driver.getCurrentUrl());
058        WebElement downloadLink = getPackageDownloadLink(packageId);
059        if (downloadLink != null) {
060            downloadLink.click();
061            return getPackageInstallLink(packageId);
062        }
063        return null;
064    }
065
066    public PackageInstallationScreen getInstallationScreen(String packageId) {
067        WebElement installLink = getPackageInstallLink(packageId);
068        if (installLink == null) {
069            return null;
070        }
071        installLink.click();
072        return asPage(PackageInstallationScreen.class);
073    }
074
075    public UpdateCenterPage exit() {
076        driver.switchTo().defaultContent();
077        return asPage(UpdateCenterPage.class);
078    }
079
080}