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 SearchProduct(string search)
        {
            Console.WriteLine("Textbox 'Search':");
            SeleniumSetMethods.ElementDisplayedAndEnabled(txtSearch);

            SeleniumSetMethods.StepStart("Clears textbox 'Search'.", "3");
            SeleniumSetMethods.Clears(txtSearch);
            SeleniumSetMethods.ElementEmpty(txtSearch);

            SeleniumSetMethods.StepStart("Enters text 'Razer Laptop' in 'Search' textbox.", "4");
            SeleniumSetMethods.EnterText(txtSearch, search);
            string enteredtext = SeleniumGetMethods.GetValue(txtSearch);

            SeleniumGetMethods.VerifyText(enteredtext, search);
            Console.WriteLine("Button 'Search':");
            SeleniumSetMethods.ElementDisplayedAndEnabled(btnSearch);

            SeleniumSetMethods.StepStart("Submits button 'Search'.", "5");
            SeleniumSetMethods.Submits(btnSearch);
            string urlSearch = WebDriver.driver.Url;

            SeleniumSetMethods.WaitForPageToLoad(WebDriver.driver, 35);
            SeleniumGetMethods.PageLoaded(urlSearch, "search");
            Console.WriteLine("Searched Links web shop for '{0}'!", search);
        }
        public static void SelectPCs()
        {
            SeleniumSetMethods.StepStart("Loads web page (https://www.links.hr/hr/).", "1");
            SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "links");

            Console.WriteLine("Button 'Računala':");
            SeleniumSetMethods.ElementDisplayedAndEnabled(btnRačunala);

            SeleniumSetMethods.StepStart("Clicks button 'Računala'.", "2");
            SeleniumSetMethods.MoveToElement(btnRačunala, WebDriver.driver);
            SeleniumSetMethods.Clicks(btnRačunala);
            string urlSorted = WebDriver.driver.Url;

            SeleniumSetMethods.WaitForPageToLoad(WebDriver.driver, 35);
            SeleniumGetMethods.PageLoaded(urlSorted, "racunala");
        }
        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));
            }
        }
示例#5
0
        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));
            }
        }