Last active
May 18, 2021 15:07
-
-
Save nadvolod/559dbdafbddad6dbb055787086437ede to your computer and use it in GitHub Desktop.
Sample good page object using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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