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 void ExecuteTest() { //Title SeleniumSetMethods.SelectDropDown(driver, "TitleId", "Mr.", "Id"); //Initial SeleniumSetMethods.EnterText(driver, "Initial", "executeautomation", "Name"); Console.WriteLine("The value from my Title is:" + SeleniumGetMethods.GetTextFromDDL(driver, "TitleId", "Id")); Console.WriteLine("The value from my Initial is:" + SeleniumGetMethods.GetText(driver, "Initial", "Name")); }
public void ThenTheLoginShouldFailWith(string p0) { this.Message = p0; var wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2)); string messagetext = SeleniumGetMethods.GetText(SaucedemoLogInPageObjects.textMessage); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='login_button_container']/div/form/h3"))); Assert.IsTrue(messagetext.Contains(Message)); SeleniumGetMethods.VerifyText(messagetext, Message); }
public void FirstTest() { //Checking the state of TextBoxes and Button SeleniumGetMethods.UserNameTextboxCheck("Username", PropertyType.Name); SeleniumGetMethods.PasswordTextboxCheck("Password", PropertyType.Name); SeleniumGetMethods.LoginButtonCheck("action", PropertyType.Name); //Click on button "Prijava" SeleniumSetMethods.Click("action", PropertyType.Name); //Getting alert message from the website Console.WriteLine("Alert message: " + SeleniumGetMethods.GetText("/html/body/div[1]/div/div/div/div/div/div/div/div", PropertyType.CssName) + "\n"); }
public void ExecuteTest() { //Title SeleniumSetMethods.SelectDropDown("TitleId", "Mr.", PropertyType.Id); //Initial SeleniumSetMethods.EnterText("Initial", "executeautomation", PropertyType.Name); Console.WriteLine("The value from my Title is: " + SeleniumGetMethods.GetText("TitleId", PropertyType.Id)); Console.WriteLine("The value from my Initial is: " + SeleniumGetMethods.GetText("Initial", PropertyType.Name)); //Click SeleniumSetMethods.Click("Save", PropertyType.Name); }
public static void SelectSize(string size) { ICollection <IWebElement> elements = SeleniumGetMethods.GetElements(Properties.driver, "//*[@id=\"w3\"]/li[1]/ul/li[2]/ul/li[1]/ul//span[1]", "xpath"); foreach (IWebElement element in elements) { if (element.Text.ToLower().Trim().Equals(size)) { element.Click(); return; } } PrintResults("Number of Results: " + SeleniumGetMethods.GetText(Properties.driver, "srp-controls__count-heading", "Class")); }
public void ExecuteTest_CustomControlMethods() { //navigate to demo site page webDriver.Navigate().GoToUrl("http://executeautomation.com/demosite/index.html?UserName=&Password=&Login=Login"); Console.WriteLine("Opened Demo Site URL"); //title SeleniumSetMethods.SelectDropDown(webDriver, "TitleId", "Mr.", "Id"); //initial SeleniumSetMethods.EnterText(webDriver, "Initial", "M", "Name"); //first name SeleniumSetMethods.EnterText(webDriver, "FirstName", "Michael", "Name"); //middle name SeleniumSetMethods.EnterText(webDriver, "MiddleName", "Lee", "Name"); //gender SeleniumSetMethods.Click(webDriver, "Female", "Name"); //languages SeleniumSetMethods.Click(webDriver, "Hindi", "Name"); //save button SeleniumSetMethods.Click(webDriver, "Save", "Name"); Console.WriteLine("Executed Save Values"); Thread.Sleep(1000); Console.WriteLine("Get New Values"); //title Console.WriteLine("Title: " + SeleniumGetMethods.GetTextFromDDL(webDriver, "TitleId", "Name")); //initial Console.WriteLine("Initial: " + SeleniumGetMethods.GetText(webDriver, "Initial", "Name")); //first name Console.WriteLine("First Name: " + SeleniumGetMethods.GetText(webDriver, "FirstName", "Name")); //middle name Console.WriteLine("Middle Name: " + SeleniumGetMethods.GetText(webDriver, "MiddleName", "Name")); Console.WriteLine("Executed Get New Values"); }
public static void LogIn(string correctusername, string correctpassword, string incorrectusername, string incorrectpassword) { try { SeleniumSetMethods.StepStart("Loads web page (https://www.saucedemo.com/).", "1"); SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "saucedemo"); Console.WriteLine("Text box 'Username':"******"Text box 'Password':"******"Button 'LOGIN':"******"\r", string.Empty); SeleniumGetMethods.VerifyText(Usernames, "Accepted usernames are:\nstandard_user\nlocked_out_user\nproblem_user\nperformance_glitch_user"); string Password = SeleniumGetMethods.GetText(textPassword).Replace("\r", string.Empty); SeleniumGetMethods.VerifyText(Password, "Password for all users:\nsecret_sauce"); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "2"); SeleniumSetMethods.Submits(buttonLOGIN); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); string message = SeleniumGetMethods.GetText(textMessage); SeleniumGetMethods.VerifyText(message, "Epic sadface: Username is required"); SeleniumSetMethods.StepStart("Enters incorrect password.", "3"); SeleniumSetMethods.EnterText(textboxPassword, incorrectpassword); string enteredtext = SeleniumGetMethods.GetValue(textboxPassword); SeleniumGetMethods.VerifyText(enteredtext, incorrectpassword); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "4"); SeleniumSetMethods.Submits(buttonLOGIN); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); message = SeleniumGetMethods.GetText(textMessage); SeleniumGetMethods.VerifyText(message, "Epic sadface: Username is required"); SeleniumSetMethods.StepStart("Clears 'Password' textbox.", "5"); SeleniumSetMethods.Clears(textboxPassword); SeleniumSetMethods.ElementEmpty(textboxPassword); SeleniumSetMethods.StepStart("Enters incorrect username.", "6"); SeleniumSetMethods.EnterText(textboxUsername, incorrectusername); enteredtext = SeleniumGetMethods.GetValue(textboxUsername); SeleniumGetMethods.VerifyText(enteredtext, incorrectusername); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "7"); SeleniumSetMethods.Submits(buttonLOGIN); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); message = SeleniumGetMethods.GetText(textMessage); SeleniumGetMethods.VerifyText(message, "Epic sadface: Password is required"); SeleniumSetMethods.StepStart("Clears 'Username' textbox.", "8"); SeleniumSetMethods.Clears(textboxUsername); SeleniumSetMethods.ElementEmpty(textboxUsername); SeleniumSetMethods.StepStart("Enters incorrect username and password.", "9"); SeleniumSetMethods.EnterText(textboxUsername, incorrectusername); SeleniumSetMethods.EnterText(textboxPassword, incorrectpassword); enteredtext = SeleniumGetMethods.GetValue(textboxUsername); SeleniumGetMethods.VerifyText(enteredtext, incorrectusername); enteredtext = SeleniumGetMethods.GetValue(textboxPassword); SeleniumGetMethods.VerifyText(enteredtext, incorrectpassword); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "10"); SeleniumSetMethods.Submits(buttonLOGIN); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); message = SeleniumGetMethods.GetText(textMessage); SeleniumGetMethods.VerifyText(message, "Epic sadface: Username and password do not match any user in this service"); SeleniumSetMethods.StepStart("Clears 'Username' and ‘Password’ textboxes.", "11"); SeleniumSetMethods.Clears(textboxUsername); SeleniumSetMethods.Clears(textboxPassword); SeleniumSetMethods.ElementEmpty(textboxUsername); SeleniumSetMethods.ElementEmpty(textboxPassword); SeleniumSetMethods.StepStart("Enters incorrect username and correct password.", "12"); SeleniumSetMethods.EnterText(textboxUsername, incorrectusername); SeleniumSetMethods.EnterText(textboxPassword, correctpassword); enteredtext = SeleniumGetMethods.GetValue(textboxUsername); SeleniumGetMethods.VerifyText(enteredtext, incorrectusername); enteredtext = SeleniumGetMethods.GetValue(textboxPassword); SeleniumGetMethods.VerifyText(enteredtext, correctpassword); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "13"); SeleniumSetMethods.Submits(buttonLOGIN); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); message = SeleniumGetMethods.GetText(textMessage); SeleniumGetMethods.VerifyText(message, "Epic sadface: Username and password do not match any user in this service"); SeleniumSetMethods.StepStart("Clears 'Username' and 'Password' textboxes.", "14"); SeleniumSetMethods.Clears(textboxUsername); SeleniumSetMethods.Clears(textboxPassword); SeleniumSetMethods.ElementEmpty(textboxUsername); SeleniumSetMethods.ElementEmpty(textboxPassword); SeleniumSetMethods.StepStart("Enters correct username and incorrect password.", "15"); SeleniumSetMethods.EnterText(textboxUsername, correctusername); SeleniumSetMethods.EnterText(textboxPassword, incorrectpassword); enteredtext = SeleniumGetMethods.GetValue(textboxUsername); SeleniumGetMethods.VerifyText(enteredtext, correctusername); enteredtext = SeleniumGetMethods.GetValue(textboxPassword); SeleniumGetMethods.VerifyText(enteredtext, incorrectpassword); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "16"); SeleniumSetMethods.Submits(buttonLOGIN); Console.WriteLine("Button 'X':"); SeleniumSetMethods.ElementDisplayedAndEnabled(buttonX); message = SeleniumGetMethods.GetText(textMessage); SeleniumGetMethods.VerifyText(message, "Epic sadface: Username and password do not match any user in this service"); SeleniumSetMethods.StepStart("Clears 'Username' and 'Password' textboxes.", "17"); SeleniumSetMethods.Clears(textboxUsername); SeleniumSetMethods.Clears(textboxPassword); SeleniumSetMethods.ElementEmpty(textboxUsername); SeleniumSetMethods.ElementEmpty(textboxPassword); SeleniumSetMethods.StepStart("Enters correct username and correct password.", "18"); SeleniumSetMethods.EnterText(textboxUsername, correctusername); SeleniumSetMethods.EnterText(textboxPassword, correctpassword); enteredtext = SeleniumGetMethods.GetValue(textboxUsername); SeleniumGetMethods.VerifyText(enteredtext, correctusername); enteredtext = SeleniumGetMethods.GetValue(textboxPassword); SeleniumGetMethods.VerifyText(enteredtext, correctpassword); SeleniumSetMethods.StepStart("Submits button 'LOGIN'.", "19"); SeleniumSetMethods.Submits(buttonLOGIN); string urlInventory = WebDriver.driver.Url; SeleniumSetMethods.WaitForPageToLoad(WebDriver.driver, 35); SeleniumGetMethods.PageLoaded(urlInventory, "inventory"); Console.WriteLine("Login successful!"); } catch (Exception e) { throw new Exception(String.Format("Test failed! {0}", e.StackTrace)); } }
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)); } }