Reputation: 9121
I am building a testing framework for a website using Page Object Model with Selenium
I am thinking that in general if I have two pages with the exact user controls and functions but different URLs I should create one father page class that has two classes inheriting from it. But what if I have the same two pages with different locators for controls? what do you think? do you think that creating a totally separate class for every page will be a good practice? or is there a way to let the children classes override locators? knowing that I am using PageFactory.
Here is an example
public class Header
{
[FindsBy(How = How.ClassName, Using = "logout_button")]
public IWebElement BtnLogout { get; set; }
public Header()
{
PageFactory.InitElements(Browser.Driver, this);
}
public void Logout()
{
this.BtnLogout.Click();
}
}
public class SecondHeader
{
[FindsBy(How = How.ClassName, Using = "logout")]
public IWebElement BtnLogout { get; set; }
public Header()
{
PageFactory.InitElements(Browser.Driver, this);
}
public void Logout()
{
this.BtnLogout.Click();
}
}
Upvotes: 0
Views: 884
Reputation: 1138
You can do like this:
public class Header
{
[FindsBy(How = How.ClassName, Using = "logout_button")]
public virtual IWebElement BtnLogout { get; set; }
public Header()
{
PageFactory.InitElements(Browser.Driver, this);
}
public void Logout()
{
this.BtnLogout.Click();
}
}
public class SecondHeader: Header
{
[FindsBy(How = How.ClassName, Using = "logout")]
public overidde IWebElement BtnLogout { get; set; }
}
Upvotes: 2