Beispiel #1
0
        private static bool ClickStaySignedIn(IWebDriver driver)
        {
            var xpath   = By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]);
            var element = driver.ClickIfVisible(xpath, 5.Seconds());

            return(element != null);
        }
        /// <summary>
        /// Logs into the given instance with the given credentials.
        /// </summary>
        /// <param name="driver">WebDriver used to imitate user actions.</param>
        /// <param name="orgUrl">The <see cref="Uri"/> of the instance.</param>
        /// <param name="username">The username of the user.</param>
        /// <param name="password">The password of the user.</param>
        public static void Login(IWebDriver driver, Uri orgUrl, string username, string password)
        {
            driver.Navigate().GoToUrl(orgUrl);
            driver.ClickIfVisible(By.Id("otherTile"));

            bool waitForMainPage = WaitForMainPage(driver);

            if (!waitForMainPage)
            {
                IWebElement usernameInput = driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.UserId]), 30.Seconds());
                usernameInput.SendKeys(username);
                usernameInput.SendKeys(Keys.Enter);

                IWebElement passwordInput = driver.WaitUntilClickable(By.XPath(Elements.Xpath[Reference.Login.LoginPassword]), 30.Seconds());
                passwordInput.SendKeys(password);
                passwordInput.Submit();

                var staySignedIn = driver.WaitUntilClickable(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]), 10.Seconds());
                if (staySignedIn != null)
                {
                    staySignedIn.Click();
                }

                WaitForMainPage(driver, 30.Seconds());
            }
        }
Beispiel #3
0
        private static LoginResult Login(IWebDriver driver, WebClient client, Uri uri, SecureString username, SecureString password)
        {
            bool online = !(client.OnlineDomains != null && !client.OnlineDomains.Any(d => uri.Host.EndsWith(d)));

            driver.Navigate().GoToUrl(uri);

            if (!online)
            {
                return(LoginResult.Success);
            }

            driver.WaitUntilClickable(By.Id("use_another_account_link"), TimeSpan.FromSeconds(1), e => e.Click());

            bool success = EnterUserName(driver, username);

            driver.ClickIfVisible(By.Id("aadTile"));
            client.Browser.ThinkTime(1000);

            EnterPassword(driver, password);
            client.Browser.ThinkTime(1000);

            int attempts = 0;

            do
            {
                success = ClickStaySignedIn(driver) || WaitForMainPage(driver, 15);
                attempts++;
            }while (!success && attempts <= 3);

            if (success)
            {
                WaitForMainPage(driver, 60);
            }
            else
            {
                throw new InvalidOperationException("Login failed");
            }

            return(success ? LoginResult.Success : LoginResult.Failure);
        }