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