Skip to content

Instantly share code, notes, and snippets.

@nadvolod
Last active May 18, 2021
Embed
What would you like to do?
Sample good page object using C#
public class ProductsPage : BasePage
{
private readonly string _pageUrlPart;
public ProductsPage(IWebDriver driver) : base(driver)
{
_pageUrlPart = "inventory.html";
}
// An element can be located using ExpectedConditions through an explicit wait
public bool IsLoaded => Wait.UntilIsDisplayedById("inventory_filter_container");
//elements are not accessible for the external test API
private IWebElement LogoutLink => _driver.FindElement(By.Id("logout_sidebar_link"));
// An element can also be located without ExpectedConditions
private IWebElement HamburgerElement => _driver.FindElement(By.ClassName("bm-burger-button"));
public int ProductCount =>
_driver.FindElements(By.ClassName("inventory_item")).Count;
//We are using Composition to have one page object living in another page object
public CartComponent Cart => new CartComponent(_driver);
public void Logout()
{
HamburgerElement.Click();
LogoutLink.Click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment