I use Pagefactory design pattern for selenium java tests and things work just fine. I am wondering if it is possible to call a PageFactory instance only once for multiple actions instead of repeating the instance all the time in the same method. I have something like this:
private static BasePage basePage; //There is BasePage class somewhere that holds PageFactory elements
basePage = PageFactory.initElements(driver, BasePage.class); // PageFactory initialisation in the test class
public static void loginTest() throws InterruptedException {
basePage.acceptButton.click();
basePage.skipButton.click();
basePage.loginButton.click();
}
I am repeating the basePage
every time I perform an action. I am thinking if there is a way with java to call the basePage
instance only once. I tried something like this:
basePage.acceptButton.click()
.skipButton.click();
.loginButton.click();
The code is unable to compile. Is there a workaround or is this beyond java?