Disable Integrated Windows Authentication (IWA) for Selenium

Here’s the problem:

You have a site that you’d like to write automated tests for.  But when you attempt to login with Internet Explorer, it has a Windows Authentication dialog popup. Because this is a native UI element, Selenium can’t touch it.

If you have control of the machine (and the Windows ADFS domain controller), you can add the user and the popup will go away.  But if you don’t have control — like if you’re running your tests on a virtual machine in the cloud with Sauce Labs — you need to find a way to get around it.

I recently ran into this problem.  It only affected Internet Explorer.  Chrome and Firefox were directed to a web login form — which could be automated with Selenium.  The options were to either A) figure out how to authenticate with Windows, or B) bypass Windows Authentication so it doesn’t have the native popup, and it doesn’t block tests.

I think I’ve found a solution.

You can disable Integrated Windows Authentication under “Internet Options” for Internet Explorer.  Under the “Advanced” tab, scroll down to “Security” and uncheck “Enable Integrated Windows Authentication”.  That should do it.

 

 

But there was still the task of automating this step.  I thought of trying a macro tool like AutoIt, but that just didn’t feel right.  Plus, it can be tricky to actually use AutoIt.  I don’t want to learn their language, and the recorder has been removed from AutoIt.

Click here to see how to get an older version of AutoIt that still has a working recorder:

https://www.autoitscript.com/forum/topic/176009-where-is-au3recordexe/

I knew there must be some way to do this without resorting to UI automation.  So, after a little poking around, I found this old blog post:

https://laxmanchip.wordpress.com/2011/12/16/enabledisable-integrated-windows-authentication-vbscript/

Thanks Tom!

A little more searching taught me all I need to know about using Powershell to edit registry keys:

https://blogs.technet.microsoft.com/heyscriptingguy/2015/04/02/update-or-add-registry-key-value-with-powershell/

Combining the two gave me this nice little script:

Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -name EnableNegotiate -value 0
Get-Item "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

 

And now I can execute that on a remote computer before running my Selenium automation!

Sauce Labs has the following in their wiki about using AutoIt as a pre-run executable:

https://wiki.saucelabs.com/display/DOCS/Running+an+AutoIt+Script+as+a+Pre-run+Executable+to+Handle+Windows+Security+Authentication+Dialogs

And some general information about specifying a pre-run executable in your Desired Capabilities.

Thanks Sauce Labs!

And thanks to the team that set up this challenge — you know who you are ;)

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s