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 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 By getNextButtonLocator() { 058 return By.xpath(REGISTER_DIV_LOCATOR.replace("CSS_CLASS", "ui blue submit button btnNext")); 059 } 060 061 @Override 062 protected By getPreviousButtonLocator() { 063 return By.xpath(REGISTER_DIV_LOCATOR.replace("CSS_CLASS", "ui blue submit button btnPrev")); 064 } 065 066 public ConnectWizardPage openLink(String text) { 067 ConnectWizardPage wpage = openLink(ConnectWizardPage.class, text); 068 if (!driver.getCurrentUrl().contains(CONNECT_IFRAME_URL_PATTERN)) { 069 driver.switchTo().frame("connectForm"); 070 return asPage(ConnectWizardPage.class); 071 } 072 return wpage; 073 } 074 075 public ConnectWizardPage submitWithError() { 076 return next(ConnectWizardPage.class, 077 input -> findElementWithTimeout(By.cssSelector(".warning.message li"), 5 * 1000) != null); 078 } 079 080 public <T extends AbstractPage> T openLink(Class<T> wizardPageClass, String text) { 081 WebElement link = findElementWithTimeout(By.linkText(text)); 082 if (link == null) { 083 return null; 084 } 085 waitUntilEnabled(link); 086 link.click(); 087 return asPage(wizardPageClass); 088 } 089 090 public String getTitle2() { 091 WebElement title2 = findElementWithTimeout(By.xpath("//h2")); 092 if (title2 == null) { 093 return null; 094 } 095 return title2.getText(); 096 } 097 098}