示例#1
0
        public void WhenISubmitLOGINButton()
        {
            var wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2));

            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("login-button")));
            SeleniumSetMethods.Submits(SaucedemoLogInPageObjects.buttonLOGIN);
        }
        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);
        }
示例#3
0
        public void GivenILoggedIn()
        {
            WebDriver.driver.Navigate().GoToUrl("https://www.saucedemo.com/");
            SeleniumGetMethods.PageLoaded(WebDriver.driver.Url, "saucedemo");
            var wait = new WebDriverWait(WebDriver.driver, TimeSpan.FromSeconds(2));

            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("login-button")));
            SeleniumSetMethods.EnterText(SaucedemoLogInPageObjects.textboxUsername, "standard_user");
            SeleniumSetMethods.EnterText(SaucedemoLogInPageObjects.textboxPassword, "secret_sauce");
            SeleniumSetMethods.Submits(SaucedemoLogInPageObjects.buttonLOGIN);
        }
        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));
            }
        }