硒的页面对象模型和页面工厂有什么不同?
问题描述:
因为看起来页面对象模型和页面工厂都在做同样的事情。所以我很困惑。硒的页面对象模型和页面工厂有什么不同?
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
是初始化您希望在创建它的一个实例的页对象中与交互的网络元素的方式。
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是偏析基于网页硒代码的设计模式。
例:登录页面的主页等
2 ..页面对象模型是代表在测试框架的应用程序的方式创建一个单独的Java类,一个多类。对于应用程序中的每个“页面”,都会创建一个页面对象来引用“页面”。
页面出厂
1 ..高级概念(POM +新功能)或
元件使用@FindBy或@FindBys注释
首字母缩略词的所有元素识别一次在第1点宣布。
(POM中,初始化发生在飞行中)
PageFactory.initElements(驱动程序,这一点);
2.页面工厂是实现页面对象模型的一种方式。为了支持页面对象模式,WebDriver的支持库包含一个工厂类。