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