概述
package demo; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; public class HomePage { public String base_url = "https://www.baidu.com/"; public WebDriver driver; WebElement inputBox; WebElement searchButton; /** * @author Young * @param message */ public void typeInputBox(String message) { inputBox = driver.findElement(By.id("kw")); inputBox.clear(); inputBox.sendKeys(message); } /** * @author Young */ public void clickSearchButton() { searchButton = driver.findElement((By.cssSelector("input#su"))); searchButton.click(); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); } /** * @author Young * @param d */ HomePage(WebDriver d) { this.driver = d; driver.get(base_url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); } /** * @author Young * @return */ public String getTitle() { return driver.getTitle(); } }
Page factory:
package demo; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; public class HomePage { public String base_url = "https://www.baidu.com/"; public WebDriver driver; @FindBy(how = How.ID, using = "kw") WebElement inputBox; @FindBy(how = How.CSS, using = "input#su") WebElement searchButton; /** * @author Young * @param message */ public void typeInputBox(String message) { inputBox.clear(); inputBox.sendKeys(message); } /** * @author Young */ public void clickSearchButton() { searchButton.click(); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); } /** * @author Young * @param d */ HomePage(WebDriver d) { this.driver = d; driver.get(base_url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this); } /** * @author Young * @return */ public String getTitle() { return driver.getTitle(); } }
转载于:https://www.cnblogs.com/tobecrazy/p/5008432.html
最后
以上就是飞快书包为你收集整理的selenium page object & Page Factory的全部内容,希望文章能够帮你解决selenium page object & Page Factory所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复