因爲看起來頁面對象模型和頁面工廠都在做同樣的事情。所以我很困惑。硒的頁面對象模型和頁面工廠有什麼不同?
IpmObjectInitializer initialize = new IpmObjectInitializer(driver.getWebDriver());
//在BatchCreationPageFactory類
batchCreationPageFactory = initialize.getBatchCreationPageFactoryObj();
因爲看起來頁面對象模型和頁面工廠都在做同樣的事情。所以我很困惑。硒的頁面對象模型和頁面工廠有什麼不同?
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的支持庫包含一個工廠類。