I am developing a WebDriver [Java] selenium structure in which there is a base class, and every other class extends from this class. In addition, I follow the Page Object Model, where each page corresponds to a class and the method in which it moves to the next page returns a new instance of the next page / class. In short, each page of the user interface corresponds to a class
Now every page has some common functions, so instead of putting them in every class and avoiding DRY, I put this in the base page class
for ex goBack, the method is on every page, which basically moves to the previous page.
My concern is that I want to keep track of the chain between pages / classes and, therefore, I'm not sure what the return type of common ex goBack methods should be.
Remember that any method that goes to the next page should return a new instance of this page.
One solution I thought was introducing Generics, but still struggling. Can someone help me on how I can achieve this.
public class BasePage { public WebDriver driver; public BasePage(WebDriver driver) { this.driver=driver; } public BasePage clickGoBack() throws Exception{ driver.click(goBackButton); return this; } }
source share