Authentication Pop up
There are times when we get an authentication pop up when we hit application url based on the authentication type set by the network/application servers. How do we handle such kind of pop ups?
HTTP Basic Authentication
For a basic http authentication, we can prepend the credentials to the proxy server and that works as usual. For example, we can do the following.
@browser = Watir::Browser.new :firefox
@browser = Selenium::Driver.for :firefox
We can place the above code in hooks.rb file in our cucumber project in the Before block
NTLM/CNTLM Authentication – Solution 1
With this type of authentication, the above code will not work. Typically, we will see a pop up message as below. Even after you input your credentials and ask the browser to save those, still the pop up would show up again.
We talked about a couple of options in Firefox profile section by changing the about:config settings, however with NTLM, none of those were very helpful. So how do we handle this?
We will need to rely on an external add-on for firefox called AutoAuth.
1) Click Add-ons under manage button in firefox
2) Search for Autoauth and then click install
3) Auto Auth should appear after installation
Login once again and save creds
After restarting firefox, now login again and supply the credentials and save the credentials this time. Now Autoauth will automatically record your actions of entering the credentials in the NTLM pop up window and save your credentials.
That is it !
Now whenever you hit the url, autoauth will be listening behind and if it sees the window, then it logs in with your credentials, so that you pass through that point.
NTLM/CNTLM Authentication – Firefox Profile – Solution 2
In the above case, we have used the firefox “default” profile and saved our credentials and also installed Auto auth add on. However we might want to keep it flexible as per below
- I want a separate firefox profile while doing Automation and keep auto auth only to that profile
- I don’t want to install auto auth, instead the automation scripts should load that add-on when executing the scripts
The above two requirements make the tests look cleaner and more manageable. So how do we do that? Lets get right into it.
1) Lets create a new firefox profile.
I named it seleniumprofile. From command line type “firefox.exe” [There should be no firefox windows open at this point]
Click “create profile” and complete the workflow and save the profile to anywhere on your file system
2) Launch the browser with “seleniumprofile”
3) Login and save creds
After starting firefox, now login again and supply the credentials and save the credentials this time.
4) Download Auto auth
5) Save the .xpi file
Start firefox with profile and Auto auth
Now create a browser instance as below [Or modify in hooks.rb if using cucumber project]
profile = Selenium::WebDriver::Firefox::Profile.from_name 'seleniumprofile'
@browser = Watir::Browser.new :firefox, profile: profile
We can see this time that auto auth fills the credentials for us and the automation scripts will move smoothly from here on.