gpt4 book ai didi

java - selenium 中的页面对象模型和页面工厂有什么区别?

转载 作者:行者123 更新时间:2023-12-01 07:03:08 25 4
gpt4 key购买 nike

看起来页面对象模型和页面工厂正在做同样的事情。所以我很困惑。

IpmObjectInitializer initialize = new IpmObjectInitializer(driver.getWebDriver());

//初始化 BatchCreationPageFactory 类中的元素

batchCreationPageFactory = initialize.getBatchCreationPageFactoryObj();

最佳答案

页面对象是一个表示网页并包含功能和成员的类。

public class LogInPage
{
private WebElement userName;
private WebElement password;

public LogInPage() {
}

public void locateElements() {
userName = driver.findElement(By.id("userName"));
password = driver.findElement(By.id("password"));
}

public void doLogIn() {
userName.sendKeys("qwe");
password.sendKeys("123");
}
}

Page Factory 是一种在创建页面对象实例时初始化要在页面对象中与之交互的 Web 元素的方法。

public class LogInPage
{
@FindBy(id="userName")
private WebElement userName;

@FindBy(id="password")
private WebElement password;

public LogInPage() {
PageFactory.initElements(driver, this); // initialize the members like driver.findElement()
}

public void doLogIn() {
userName.sendKeys("qwe");
password.sendKeys("123");
}
}

关于java - selenium 中的页面对象模型和页面工厂有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35866113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com