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 java.util.ArrayList;
023import java.util.List;
024
025import org.nuxeo.functionaltests.AbstractTest;
026import org.openqa.selenium.By;
027import org.openqa.selenium.WebDriver;
028import org.openqa.selenium.WebElement;
029
030public class WizardPage extends AbstractWizardPage {
031
032    protected static final String NEXT_BUTTON_LOCATOR = "id('btnNext')";
033
034    protected static final String PREV_BUTTON_LOCATOR = "id('btnPrev')";
035
036    public WizardPage(WebDriver driver) {
037        super(driver);
038        IFrameHelper.focusOnWizardPage(driver);
039    }
040
041    public WizardPage next() {
042        return next(false);
043    }
044
045    public WizardPage next(Boolean errorExpected) {
046        if (errorExpected) {
047            return next(WizardPage.class, driver -> hasError());
048        } else {
049            return next(WizardPage.class);
050        }
051    }
052
053    public WizardPage previous() {
054        return previous(false);
055    }
056
057    public WizardPage previous(Boolean errorExpected) {
058        if (errorExpected) {
059            return previous(WizardPage.class, driver -> hasError());
060        } else {
061            return previous(WizardPage.class);
062        }
063    }
064
065    @Override
066    protected By getNextButtonLocator() {
067        return By.xpath(NEXT_BUTTON_LOCATOR);
068    }
069
070    @Override
071    protected By getPreviousButtonLocator() {
072        return By.xpath(PREV_BUTTON_LOCATOR);
073    }
074
075    public ConnectWizardPage getConnectPage() {
076        AbstractTest.switchToPopup("/register/#/embedded");
077        return AbstractTest.asPage(ConnectWizardPage.class);
078    }
079
080    public boolean hasError() {
081        return getErrors().size() > 0;
082    }
083
084    public List<String> getErrors() {
085        List<WebElement> errorsEl = driver.findElements(By.xpath("//div[@class='errBlock']/div[@class='errItem']"));
086        List<String> errors = new ArrayList<String>();
087        for (WebElement errorEl : errorsEl) {
088            if (errorEl.getText() != null && errorEl.getText().length() > 0) {
089                errors.add(errorEl.getText());
090            }
091        }
092        return errors;
093    }
094
095    public List<String> getInfos() {
096        List<WebElement> infosEl = driver.findElements(By.xpath("//div[@class='infoBlock']/div[@class='infoItem']"));
097        List<String> infos = new ArrayList<String>();
098        for (WebElement infoEl : infosEl) {
099            if (infoEl.getText() != null && infoEl.getText().length() > 0) {
100                infos.add(infoEl.getText());
101            }
102        }
103        return infos;
104    }
105
106    public boolean hasInfo() {
107        return getInfos().size() > 0;
108    }
109
110    public String getTagText(String tag) {
111        WebElement tagElt = findElementWithTimeout(By.xpath("//" + tag));
112        if (tagElt == null) {
113            return null;
114        }
115        return tagElt.getText();
116    }
117
118}