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:
Thanks Tom!
A little more searching taught me all I need to know about using Powershell to edit registry keys:
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:
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 ;)