public static void CartPage() { SeleniumSetMethods.StepStart("Loads web page (https://www.saucedemo.com/cart.html).", "1"); SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "cart"); Console.WriteLine("Menu button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonMenu); Console.WriteLine("Cart button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonCart); string text = SeleniumGetMethods.GetText(textcart); SeleniumGetMethods.VerifyText(text, "1"); Console.WriteLine("Main text:"); text = SeleniumGetMethods.GetText(textMain); SeleniumGetMethods.VerifyText(text, "Your Cart"); Console.WriteLine("'QTY' text:"); text = SeleniumGetMethods.GetText(textQuantity); SeleniumGetMethods.VerifyText(text, "QTY"); Console.WriteLine("'DESCRIPTION' text:"); text = SeleniumGetMethods.GetText(textDescription); SeleniumGetMethods.VerifyText(text, "DESCRIPTION"); SeleniumGetMethods.VerifyProduct(cartproductcontainer, "1\nSauce Labs Backpack\ncarry.allTheThings() with the sleek, streamlined Sly Pack that melds uncompromising style with unequaled laptop and tablet protection.\n29.99REMOVE"); Console.WriteLine("'CONTINUE SHOPPING' button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonContinue); Console.WriteLine("'CHECKOUT' button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonCheckout); Console.WriteLine("Twitter button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonTwitter); Console.WriteLine("Fcebook button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonFacebook); Console.WriteLine("LinkedIn button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonLinkedIn); text = SeleniumGetMethods.GetText(textBottom); SeleniumGetMethods.VerifyText(text, "© 2021 Sauce Labs. All Rights Reserved. Terms of Service | Privacy Policy"); SeleniumSetMethods.StepStart("Clicks Menu button.", "2"); SeleniumSetMethods.Clicks(buttonMenu); var wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2)); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='menu_button_container']/div/div[3]/div[2]/div"))); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); Console.WriteLine("Button 'All Items':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonAllItems); Console.WriteLine("Button 'About':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonAbout); Console.WriteLine("Button 'Logout':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonLogout); Console.WriteLine("Button 'Reset App State':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonResetAppState); SeleniumSetMethods.StepStart("Clicks button 'X' ", "3"); SeleniumSetMethods.Clicks(buttonX); Thread.Sleep(2000); SeleniumSetMethods.ElementHidden(buttonX); SeleniumSetMethods.StepStart("Clicks 'CHECKOUT' button.", "4"); SeleniumSetMethods.Clicks(buttonCheckout); SeleniumSetMethods.WaitForPageToLoad(WebDriver.driver, 35); SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "checkout-step-one"); }
public static void InventoryPage() { try { SeleniumSetMethods.StepStart("Loads web page (https://www.saucedemo.com/inventory.html).", "1"); SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "inventory"); Console.WriteLine("Menu button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonMenu); Console.WriteLine("Cart button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonCart); Console.WriteLine("Main text:"); string text = SeleniumGetMethods.GetText(textMain); SeleniumGetMethods.VerifyText(text, "Products"); Console.WriteLine("DropDown menu:"); SeleniumSetMethods.ElementDisplayedAndEnabled(dropdownFilter); Console.WriteLine("Product List:"); SeleniumGetMethods.VerifyProduct(productcontainer, "Sauce Labs Backpack\ncarry.allTheThings() with the sleek, streamlined Sly Pack that melds uncompromising style with unequaled laptop and tablet protection.\n$29.99\nADD TO CART"); SeleniumGetMethods.VerifyProduct(productcontainer, "Sauce Labs Bike Light\nA red light isn't the desired state in testing but it sure helps when riding your bike at night. Water-resistant with 3 lighting modes, 1 AAA battery included.\n$9.99\nADD TO CART"); SeleniumGetMethods.VerifyProduct(productcontainer, "Sauce Labs Bolt T-Shirt\nGet your testing superhero on with the Sauce Labs bolt T-shirt. From American Apparel, 100% ringspun combed cotton, heather gray with red bolt.\n$15.99\nADD TO CART"); SeleniumGetMethods.VerifyProduct(productcontainer, "Sauce Labs Fleece Jacket\nIt's not every day that you come across a midweight quarter-zip fleece jacket capable of handling everything from a relaxing day outdoors to a busy day at the office.\n$49.99\nADD TO CART"); SeleniumGetMethods.VerifyProduct(productcontainer, "Sauce Labs Onesie\nRib snap infant onesie for the junior automation engineer in development. Reinforced 3-snap bottom closure, two-needle hemmed sleeved and bottom won't unravel.\n$7.99\nADD TO CART"); SeleniumGetMethods.VerifyProduct(productcontainer, "Test.allTheThings() T-Shirt (Red)\nThis classic Sauce Labs t-shirt is perfect to wear when cozying up to your keyboard to automate a few tests. Super-soft and comfy ringspun combed cotton.\n$15.99\nADD TO CART"); Console.WriteLine("Twitter button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonTwitter); Console.WriteLine("Fcebook button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonFacebook); Console.WriteLine("LinkedIn button:"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonLinkedIn); text = SeleniumGetMethods.GetText(textbottom); SeleniumGetMethods.VerifyText(text, "© 2021 Sauce Labs. All Rights Reserved. Terms of Service | Privacy Policy"); SeleniumSetMethods.StepStart("Clicks Dropdown Menu.", "2"); SeleniumSetMethods.Clicks(dropdownFilter); text = SeleniumGetMethods.GetText(dropdownFilter).Replace("\r", string.Empty); SeleniumGetMethods.VerifyText(text, "Name (A to Z)\nName (Z to A)\nPrice (low to high)\nPrice (high to low)"); SeleniumSetMethods.StepStart("Clicks Menu button.", "3"); SeleniumSetMethods.Clicks(buttonMenu); var wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2)); wait.Until(ExpectedConditions.ElementIsVisible(By.Id("react-burger-cross-btn"))); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); Console.WriteLine("Button 'All Items':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonAllitems); Console.WriteLine("Button 'About':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonAbout); Console.WriteLine("Button 'Logout':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonLogout); Console.WriteLine("Button 'Reset App State':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonResetappstate); SeleniumSetMethods.StepStart("Clicks button 'X'.", "4"); SeleniumSetMethods.Clicks(buttonX); wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2)); wait.Until(ExpectedConditions.ElementIsVisible(By.Id("react-burger-menu-btn"))); SeleniumSetMethods.ElementHidden(buttonX); SeleniumSetMethods.StepStart("Clicks Sauce Labs Backpack 'ADD TO CART' button.", "5"); SeleniumSetMethods.Clicks(buttonaddtocart); text = SeleniumGetMethods.GetText(buttonaddtocart); SeleniumGetMethods.VerifyText(text, "REMOVE"); Console.WriteLine("'REMOVE' button:"); text = SeleniumGetMethods.GetText(textCart); Console.WriteLine("Cart button:"); SeleniumGetMethods.VerifyText(text, "1"); SeleniumSetMethods.StepStart("Clicks Cart button.", "6"); wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2)); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='shopping_cart_container']"))); SeleniumSetMethods.Clicks(buttonCart); SeleniumSetMethods.WaitForPageToLoad(WebDriver.driver, 35); SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "cart"); } catch (Exception e) { throw new Exception(String.Format("Test failed! {0}", e.Message)); } }