コード例 #1
0
        private bool InternalSignIn(WebBrowser browser)
        {
            browser.NavigateToBasePage();
            if (!String.IsNullOrEmpty(UserLogin))
            {
                WebElementExtensions.WaitForElement(
                    browser.WebDriver,
                    TimeSpan.FromSeconds(5),
                    By.Id("ctl00_FullRegion_LoginControl_UserName"));

                var userNameElement = browser.FindElementSafe(By.Id("ctl00_FullRegion_LoginControl_UserName"));
                if (userNameElement == null || !userNameElement.Displayed)
                {
                    Console.WriteLine("Login control not found");                    
                    Console.WriteLine("URL: {0} ", browser.WebDriver.Url);                    
                    return false;
                }
                
                browser.WebDriver.FindElement(By.Id("ctl00_FullRegion_LoginControl_UserName")).Clear();
                browser.WebDriver.FindElement(By.Id("ctl00_FullRegion_LoginControl_UserName")).SendKeys(UserLogin);
                browser.WebDriver.FindElement(By.Id("ctl00_FullRegion_LoginControl_Password")).Clear();
                browser.WebDriver.FindElement(By.Id("ctl00_FullRegion_LoginControl_Password")).SendKeys(UserPassword);
                browser.WebDriver.FindElement(By.Id("ctl00_FullRegion_LoginControl_Button1")).ClickAndWaitForPageToLoad(browser.WebDriver);
                
                //wait for serwer response
                var cookieName = browser.WebDriver.Manage().Cookies.GetCookieNamed(".EPiServerLogin");
                int loginWaitCount = 10;
                while(cookieName == null)
                {
                    Console.WriteLine("Auth cookie not found, retry ");
                    if(loginWaitCount <= 0)
                        break;                    
                    loginWaitCount--;
                    Thread.Sleep(250); //TODO: read from configuration
                    cookieName = browser.WebDriver.Manage().Cookies.GetCookieNamed(".EPiServerLogin");
                }

                return cookieName != null;
            }
            return true;
        }