Reputation: 120
How to to extend and page object class and override the data?
Every page id same but some pages the searchbox will not be there or will be different so:
public class BasePageObject {
public WebDriver driver;
@FindBy(id = "searchbox")
WebElement searchBox;
public BasePageObject(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
public class HomePage extends BasePageObject {
// overide the base element id somehow?
@FindBy(id = "searchbox2")
WebElement searchBox;
public HomePage(WebDriver driver) {
super(driver);
}
}
Upvotes: 0
Views: 1375
Reputation: 1761
Just don't put the search box in BasePageObject. Only include it in the children that do have a search box. BasePageObject should only have the elements that are common across all of the children.
Upvotes: 2