Пример #1
0
        public void PriceSearchProductPageCompare()
        {
            browser.goTo("https://rozetka.com.ua/");

            var           d    = browser.driver;
            WebDriverWait wait = new WebDriverWait(d, new TimeSpan(0, 1, 0));

            IWebElement searchInput = d.FindElement(By.ClassName("search-form__input"));

            searchInput.SendKeys("dell latitude 5290");
            wait.Until(nd => nd.FindElements(By.ClassName("suggest-goods__price")).Count > 0);

            IWebElement firstElementOfSearch = d.FindElements(By.ClassName("suggest-goods__price"))[0];

            Func <string, string> parsePrice = (string p) => string.Join("", p.Where(char.IsDigit).ToArray());
            double searchPrice = double.Parse(parsePrice(firstElementOfSearch.Text));

            firstElementOfSearch.Click();
            wait.Until(nd => nd.FindElement(By.ClassName("product-prices__big")));

            IWebElement primaryElement = d.FindElement(By.ClassName("product-prices__big"));
            double      primaryPrice   = double.Parse(parsePrice(primaryElement.Text));

            Assert.AreEqual(primaryPrice, searchPrice);

            d.Navigate().Back();
            wait.Until(nd => nd.FindElement(By.ClassName("search-form__input")));

            searchInput = d.FindElement(By.ClassName("search-form__input"));
            searchInput.SendKeys("dell latitude 5290");
            wait.Until(nd => nd.FindElements(By.ClassName("suggest-goods__price")).Count > 0);
            IWebElement newFirstElementOfSearch = d.FindElements(By.ClassName("suggest-goods__price"))[0];
            double      newSearchPrice          = double.Parse(parsePrice(newFirstElementOfSearch.Text));

            Console.WriteLine($"This is repeat #{reps++}");
            Console.WriteLine($"First search price: {searchPrice}");
            Console.WriteLine($"product page price: {primaryPrice}");
            Console.WriteLine($"Second search price: {newSearchPrice}\n");
            Assert.AreEqual(newSearchPrice, searchPrice, primaryPrice);
        }
Пример #2
0
        public void Login()
        {
            var faker = new Faker();

            browser.goTo("https://ctflearn.com");

            var           d    = browser.driver;
            WebDriverWait wait = new WebDriverWait(d, new TimeSpan(0, 0, 16));

            string usernameValue = $"{faker.Name.FirstName()}{faker.Finance.Account(5)}";
            string emailValue    = faker.Internet.Email();
            string passValue     = faker.Internet.Password();

            wait.Until(nd => nd.FindElement(By.LinkText("Join Now")));
            IWebElement joinNow = d.FindElement(By.LinkText("Join Now"));

            joinNow.Click();

            wait.Until(nd => nd.FindElements(By.Id("username")));
            IWebElement usernameInput = d.FindElement(By.Id("username"));

            usernameInput.SendKeys(usernameValue);

            wait.Until(nd => nd.FindElements(By.Id("email")));
            IWebElement emailInput = d.FindElement(By.Id("email"));

            emailInput.SendKeys(emailValue);

            wait.Until(nd => nd.FindElements(By.Id("password")));
            IWebElement passwordInput = d.FindElement(By.Id("password"));

            passwordInput.SendKeys(passValue);

            wait.Until(nd => nd.FindElements(By.Id("confirm")));
            IWebElement confirmInput = d.FindElement(By.Id("confirm"));

            confirmInput.SendKeys(passValue);

            IWebElement button = d.FindElement(By.XPath("/html/body/div/div/div/div/div[1]/div[2]/form/button"));

            button.Click();
            wait.Until(nd => nd.Navigate());

            Assert.AreEqual(browser.getCurrentUrl(), "https://ctflearn.com/dashboard");

            browser.goTo("https://ctflearn.com/user/logout");
            wait.Until(nd => nd.Navigate());

            browser.goTo("https://ctflearn.com/user/login");
            wait.Until(nd => nd.Navigate());

            wait.Until(nd => nd.FindElement(By.Id("identifier")));
            IWebElement identifier = d.FindElement(By.Id("identifier"));

            identifier.SendKeys(emailValue);

            wait.Until(nd => nd.FindElement(By.Id("password")));
            IWebElement passwordLogin = d.FindElement(By.Id("password"));

            passwordLogin.SendKeys(passValue);

            wait.Until(nd => nd.FindElement(By.XPath("/html/body/div/div/div/div/div[1]/div[2]/form/button")));
            IWebElement buttonLogin = d.FindElement(By.XPath("/html/body/div/div/div/div/div[1]/div[2]/form/button"));

            buttonLogin.Click();
            wait.Until(nd => nd.Navigate());

            Assert.AreEqual(browser.getCurrentUrl(), "https://ctflearn.com/dashboard");
        }