简体   繁体   中英

Extending a page object class

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);
}

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM