Skip to content

Instantly share code, notes, and snippets.

@nadvolod
Last active May 18, 2021 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadvolod/559dbdafbddad6dbb055787086437ede to your computer and use it in GitHub Desktop.
Save nadvolod/559dbdafbddad6dbb055787086437ede to your computer and use it in GitHub Desktop.
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