Handle authentication popup in Selenium on build server

Selenium scripts are widely used for automation testing of ASP.Net web applications hosted on VSTS or TFS. These automation scripts are configured to trigger automatically on build server while Continuous Integration.

Selenium webdriver loads the webpages and navigate automatically as scripted. Some of the popular webdrivers are ChromeDriver, FirefoxDriver, IWebDriver and PythonJS.

Webdriver in automation scripts often work flawlessly in development environment by auto-login using the testing user's credentials saved in Windows Credential store. When the same scripts are ran in VSTS or TFS during Continuous Integration then the Windows auto-login fail because the VSTS servers don't have these Windows credentials to auto-populate in webdriver.

The other difference of running webdriver in development environment is that it load webpages in browser and visible to the user, but webdriver runs in background on VSTS servers.

This authentication issue can be resolved by implementing Impersonation while loading webdriver to bypass Windows authentication. Below piece of code can be used to achieve this:

using (new Impersonator("<<loginId>>", "<<domainName>>", "<<password>>");
{
   ChromeDriver driver = new ChromeDriver();
   driver.Navigate().GoToUrl("<<websiteUrl>>");
}

Impersonator class library can be found from Microsoft site.

If you are facing issue regarding domain certificate, then you can add Options in webdriver to bypass such errors.

No comments:

Post a Comment