[英]What is the differnce between page object model and page factory in selenium?
看来页面对象模型和页面工厂正在做相同的事情。 所以我很困惑。
IpmObjectInitializer initialize = new IpmObjectInitializer(driver.getWebDriver());
//初始化BatchCreationPageFactory类中的元素
batchCreationPageFactory = initialize.getBatchCreationPageFactoryObj();
Page Object
是代表网页的类,并包含功能和成员。
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");
}
}
页面对象模型(POM)
1 .. POM是一种设计模式,它根据页面分离硒代码。
例如:为“登录”页面创建一个单独的Java类,为“主页”创建一个其他类,等等。
2.页面对象模型是一种在测试框架中表示应用程序的方法。 对于应用程序中的每个“页面”,您都创建一个页面对象来引用该“页面”。
页面工厂
1 ..高级概念(POM +新功能)或
使用@FindBy或@FindBys注释标识元素
初始化一次在Point#1中声明的所有元素。
(在POM中,初始化是即时进行的)
PageFactory.initElements(driver,this);
2 ..页面工厂是实现页面对象模型的一种方法。 为了支持Page Object模式,WebDriver的支持库包含一个工厂类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.