Archief van
Tag: By

PageFactory depricated, now what??

PageFactory depricated, now what??

So one of the latest Selenium WebDriver releases depricated the PageFactory in C#. This kind of forces us to rethink our POM strategy. As somebody how has being doing the POM setup the same way for a few year now I really like this!

The “old” way:

@FindBy(css = "div[data-testid='theme']")
    private WebElement themePageButton;

public EditionPage(WebDriver driver){
    this.driver = driver;
    PageFactory.initElements(driver, this);
}

Calling the element in a method:

themePageButton.click();

So how do we still declare the element as a global variable with out using the FindBy annotation?

By to the rescue!

By themePageButtonLocator = By.cssSelector("div[data-testid='theme']");

public EditionPage(WebDriver driver){
    this.driver = driver;
}

We removed the PageFactory, the annotation and declared the By locator as a global By. We can now call the element in a method by using the By locator:

driver.findElement(themePageButtonLocator).click();

PageFactory.initElements() is gone, mission accomplished!

Please follow and like us: