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.wizard;
019
020import static org.nuxeo.functionaltests.pages.wizard.IFrameHelper.CONNECT_IFRAME_URL_PATTERN;
021
022import org.nuxeo.functionaltests.pages.AbstractPage;
023import org.openqa.selenium.By;
024import org.openqa.selenium.WebDriver;
025import org.openqa.selenium.WebElement;
026
027import com.google.common.base.Function;
028
029public class ConnectWizardPage extends AbstractWizardPage {
030
031    protected static final String REGISTER_DIV_LOCATOR = "//div[@class=\"CSS_CLASS\"]";
032
033    public ConnectWizardPage(WebDriver driver) {
034        super(driver);
035        IFrameHelper.focusOnConnectFrame(driver);
036    }
037
038    @Override
039    public String getTitle() {
040        WebElement title = findElementWithTimeout(By.xpath("//h3"));
041        return title.getText().trim();
042    }
043
044    public void exitIframe() {
045        // XXX
046    }
047
048    public String getErrorMessage() {
049        WebElement el = findElementWithTimeout(By.cssSelector("div.ui.warning.message"));
050        if (el == null) {
051            return null;
052        }
053        return el.getText().trim();
054    }
055
056    @Override
057    protected String getNextButtonLocator() {
058        return REGISTER_DIV_LOCATOR.replace("CSS_CLASS", "ui blue submit button btnNext");
059    }
060
061    @Override
062    protected String getPreviousButtonLocator() {
063        return REGISTER_DIV_LOCATOR.replace("CSS_CLASS", "ui blue submit button btnPrev");
064    }
065
066    public ConnectWizardPage getLink(String text) {
067        ConnectWizardPage wpage = getLink(ConnectWizardPage.class, text);
068        if (!driver.getCurrentUrl().contains(CONNECT_IFRAME_URL_PATTERN)) {
069            System.out.println("Oups, we are out of the frame !!!");
070            driver.switchTo().frame("connectForm");
071            return asPage(ConnectWizardPage.class);
072        }
073        return wpage;
074    }
075
076    public ConnectWizardPage submitWithError() {
077        return next(ConnectWizardPage.class, new Function<WebDriver, Boolean>() {
078            @Override
079            public Boolean apply(WebDriver input) {
080                return findElementWithTimeout(By.cssSelector(".warning.message li"), 5 * 1000) != null;
081            }
082        });
083    }
084
085    public <T extends AbstractPage> T getLink(Class<T> wizardPageClass, String text) {
086        WebElement link = findElementWithTimeout(By.linkText(text));
087        if (link == null) {
088            return null;
089        }
090        waitUntilEnabled(link);
091        link.click();
092        return asPage(wizardPageClass);
093    }
094
095    public String getTitle2() {
096        WebElement title2 = findElementWithTimeout(By.xpath("//h2"));
097        if (title2 == null) {
098            return null;
099        }
100        return title2.getText();
101    }
102
103}