コード例 #1
0
        public void User_registers_and_logs_in()
        {
            _driver.NavigateTo("");

            WebDriverWait wait = new WebDriverWait(_driver, System.TimeSpan.FromSeconds(15));

            wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));

            var userEmail    = RandomString(8) + "*****@*****.**";
            var userPassword = "******";

            {
                IWebElement registerLink = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"register_user\"]")));
                registerLink.Click();

                IWebElement emailInput = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"Input_Email\"]")));
                emailInput.SendKeys(userEmail);

                IWebElement passwordInput = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"Input_Password\"]")));
                passwordInput.SendKeys(userPassword);

                IWebElement passwordConfirmInput = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"Input_ConfirmPassword\"]")));
                passwordConfirmInput.SendKeys(userPassword);

                IWebElement registerButton = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"registerSubmit\"]")));
                registerButton.Click();

                IWebElement manageUserLink = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"manage_user\"]")));
                Assert.Contains(userEmail, manageUserLink.Text, StringComparison.InvariantCultureIgnoreCase);

                IWebElement logoutLink = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"logout_user\"]")));
                logoutLink.Click();
            }

            {
                IWebElement loginLink = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"login_user\"]")));
                loginLink.Click();

                IWebElement emailInput = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"Input_Email\"]")));
                emailInput.SendKeys(userEmail);

                IWebElement passwordInput = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"Input_Password\"]")));
                passwordInput.SendKeys(userPassword);

                IWebElement registerButton = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"login-submit\"]")));
                registerButton.Click();

                IWebElement manageUserLink = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"manage_user\"]")));
                Assert.Contains(userEmail, manageUserLink.Text, StringComparison.InvariantCultureIgnoreCase);

                IWebElement logoutLink = wait.Until(driver => driver.FindElement(By.XPath("//*[@id=\"logout_user\"]")));
                logoutLink.Click();
            }
        }
コード例 #2
0
ファイル: BooksSpec.cs プロジェクト: Euphoric/LibraryWebsite
        public void Books_list()
        {
            _driver.NavigateTo("/book-list");

            WebDriverWait wait = new WebDriverWait(_driver, System.TimeSpan.FromSeconds(15));

            wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));

            IWebElement title = wait.Until(driver => driver.FindElement(By.XPath("//h1")));

            Assert.Equal("Books", title.Text);

            var table = wait.Until(driver => driver.FindElement(By.XPath("//table")));

            IReadOnlyCollection <IWebElement> headers = table.FindElements(By.XPath("thead//th"));
            var headerTexts = headers.Select(th => th.Text).ToArray();

            Assert.Equal(new[] { "Title", "Author", "Description", "ISBN-13" }, headerTexts);

            const int defaultRowCount = 10;

            wait.Until(dr => dr.FindElements(By.XPath("//table/tbody/tr")).Count == defaultRowCount);

            // paging

            var selectedTitle = wait.Until(dr => dr.FindElement(By.XPath("//table//tr[1]/td")).Text);

            {
                var nextPageLink = _driver.FindElement(By.ClassName("pagination-next"));
                nextPageLink.Click();
            }
            wait.Until(dr => dr.Url.Contains("book-list/2", StringComparison.InvariantCulture));

            wait.Until(dr => dr.FindElement(By.XPath("//table//tr[1]/td")).Text != selectedTitle);

            selectedTitle = wait.Until(dr => dr.FindElement(By.XPath("//table//tr[1]/td")).Text);

            var lastPageLink = _driver.FindElement(By.ClassName("pagination-last"));

            lastPageLink.Click();

            wait.Until(dr => dr.FindElement(By.XPath("//table//tr[1]/td")).Text != selectedTitle);

            // TODO: Fix
            //{
            //    var nextPageLink = _driver.FindElement(By.ClassName("pagination-next"));
            //    Assert.Contains("disabled", nextPageLink.GetAttribute("class"), StringComparison.InvariantCulture);
            //}
        }