A PFM – an antipattern?
In a PFM, the initialization of all the objects is done in a method called initElements
, where the driver that controls the objects is passed as a parameter and the page gets initialized. The benefit of this is that the code for the pages is easier, as we only need the definition of the elements and/or locators (@FindBy
) and not any repetitive code for finding those elements (driver.findElement(webElement)
), which will be replaced by the use of the webElement
object directly.
The page class in this case looks like this:
PageClass.java
package package com.packtpub.PFM; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; public class PageClass { @FindBy(id=" __BVID__336") WebElement searchElement; public PageClass(WebDriver driver) { ...