using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;
using System.Collections.ObjectModel;
protected readonly IWebDriver driver;
protected readonly WebDriverWait wait;
protected readonly By homeLogoButton = By.XPath("//div[@class='container container-xl p-0']//a");
protected readonly By locator = By.XPath("");
protected readonly By element = By.XPath("");
public BasePage(IWebDriver driver)
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
protected IWebElement FindElement(By by)
return wait.Until(ExpectedConditions.ElementIsVisible(by));
protected ReadOnlyCollection<IWebElement> FindElements(By by)
return driver.FindElements(by);
protected void Type(By by, string text)
var element = FindElement(by);
protected void Click(By by)
protected string GetText(By by)
return FindElement(by).Text;
public class HomePage : BasePage
public HomePage(IWebDriver driver) : base(driver)
protected readonly By elementName = By.XPath("");
protected IWebDriver driver;
protected HomePage homePage;
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
driver = new ChromeDriver(chromeOptions);
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
homePage = new HomePage(driver);
protected void Login(string username, string password)
driver.Navigate().GoToUrl("https://www.saucedemo.com/");
loginPage.InputUsername(username);
loginPage.InputPassword(password);
loginPage.ClickLoginButton();
public class LoginTests : BaseTest
public void TestLoginWithValidCredentials()
Login("standard_user", "secret_sauce");
Assert.IsTrue(inventoryPage.IsPageLoaded(), "The login is not successfully after login with valid credentials.");
public void TestLoginWithInvalidCredentials()
Login("invalid_user123", "secret_sauce");
Assert.That(loginPage.GetErrorMessage().Contains("Username and password do not match any user in this service"), "The error message was not as expected after login with invalid credentials.");
public void TestLoginWithLockedOutUser()
Login("locked_out_user", "secret_sauce");
Assert.That(loginPage.GetErrorMessage().Contains("Sorry, this user has been locked out."), "The error message was not as expected after login with locked user.");
public class InventoryTests : BaseTest
public void InventoryTestsSetUp()
Login("standard_user", "secret_sauce");
public void TestInventoryDisplay()
Assert.IsTrue(inventoryPage.IsInventoryDisplayed(), "The items are not displayed as expected.");
Assert.IsTrue(inventoryPage.IsPageLoaded(), "The inventory page is not loaded as expected.");
public void TestAddToCartByIndex()
inventoryPage.AddToCartByIndex(1);
inventoryPage.ClickCartLink();
Assert.That(driver.PageSource.Contains("Sauce Labs Bike Light"), "The page does not contains the title of the added item");
Assert.IsTrue(cartPage.IsCartItemDisplayed(),"The cart items section is empty after adding item by index");
public void TestAddToCartByName()
inventoryPage.AddToCartByName("Sauce Labs Bike Light");
inventoryPage.ClickCartLink();
Assert.That(driver.PageSource.Contains("Sauce Labs Bike Light"), "The page does not contains the title of the added item.");
Assert.IsTrue(cartPage.IsCartItemDisplayed(),"The cart items section is empty after adding item by name.");
public void TestInventoryPageTitle()
Assert.That(inventoryPage.IsPageLoaded(), Is.True, "Inventory page is not loaded as expected.");
public class CartTests : BaseTest
public void CartTestsSetUp()
Login("standard_user", "secret_sauce");
inventoryPage.AddToCartByName("Sauce Labs Bike Light");
inventoryPage.ClickCartLink();
public void TestCartItemDisplayed()
Assert.IsTrue(cartPage.IsCartItemDisplayed(), "The added item is not displayed in the cart as expected.");
public void TestClickCheckout()
cartPage.ClickCheckout();
Assert.IsTrue(driver.Url.Contains("checkout-step-one.html"), "The checkout page is not loaded as expected.");
public class CheckoutTests : BaseTest
public void CheckoutTestsSetUp()
Login("standard_user", "secret_sauce");
inventoryPage.AddToCartByIndex(1);
inventoryPage.ClickCartLink();
cartPage.ClickCheckout();
public void TestCheckoutPageLoaded()
Assert.IsTrue(driver.Url.Contains("checkout-step-one.html"), "The checkout page is not loaded as expected.");
public void TestContinueToNextStep()
checkoutPage.EnterFirstName("TestFirstName");
checkoutPage.EnterLastName("TestLastName");
checkoutPage.EnterPostalCode("1234");
checkoutPage.ClickContinueButton();
Assert.IsTrue(driver.Url.Contains("checkout-step-two.html"), "The second checkout page is not loaded after pressing the 'continue' button.");
public void TestCompleteOrder()
checkoutPage.EnterFirstName("TestFirstName");
checkoutPage.EnterLastName("TestLastName");
checkoutPage.EnterPostalCode("1234");
checkoutPage.ClickContinueButton();
checkoutPage.ClickFinishButton();
Assert.IsTrue(driver.Url.Contains("checkout-complete.html"), "The complete page is not loaded after pressing the 'finish' button.");
Assert.IsTrue(checkoutPage.IsPageComplete(), "The order is not completed and the finish page is not loaded.");
public class HiddenMenuTests : BaseTest
public void HiddenMenuTestsSetUp()
Login("standard_user", "secret_sauce");
public void TestOpenMenu()
hiddenMenuPage.ClickMenuButton();
Assert.IsTrue(hiddenMenuPage.IsMenuOpen(), "The hidden menu is not open as expected.");
hiddenMenuPage.ClickMenuButton();
hiddenMenuPage.ClickLogoutButton();
Assert.IsTrue(driver.Url.Equals("https://www.saucedemo.com/"));