Handling internet explorer windows based authentication to a website using AutoIT script in java-cucumber-selenium automation

Sadakar Pochampalli
JasperSoft BI Suite Tutorials - Sadakar Pochampalli )


In this post, you will see tips on how to authenticate a website that is based on windows authentication. 
Reader is assumed to have some prior fundamental knowledge on the java-selenium-cucumber framework/setup. 

This post is not written to give step-by-step procedure instead written to give direct inputs on specific areas. 

Sample cucumber feature file and scenario: 

Feature: Launch internet browser and login with valid credentials
  This is a windows based authentication for sadakar.selenium.com site using internet browser.

  Scenario: Login to sadakar.selenium.com with internet explorer windows based authentication
    When I open internet explorer browser
    Then I login with username and password and navigate to sadakar.selenium.com

Problem statement : 
When you try to open sadakar.selenium.com and if the website is configured for windows based authentication as shown in below image - how do you navigate to the site using java-selenium code ? 

Click on the image to get best view of the content: 
Solution : 
1) Install latest Auto IT tool ( download : https://www.autoitscript.com/site/autoit/downloads/ )
2) Then : 
        a) Open the website with its security pop-up for windows based authentication 
        b) Open the AutoIt tool on top of the the website's windows security pop-up. 
3) Hold on "Finder Tool" on AutoIT and drag that on to the security pop-up window. 
4) Note down "Title" and "Class" in the AutoIt tool. 

Click on the image to get best view of the content: 

5) Now, in Notepad++ file write below code and save it as "autoit_ie.au3"

$sUsername = "SADA001\administrator"
$sPassword = "SADAPassWord@001"
$sTitle = WinGetTitle("Windows Security")
    If $sTitle = "Windows Security" or WinWaitActive("[CLASS:Credential Dialog Xaml Host]") or WinWaitActive("Windows Security") or WinWaitActive("iexplore.exe") or WinWaitActive("Connecting to sadakar.selenium.com")Then

6) Right click on the saved file and compile it (just compile) and you would see "autoit_ie.exe" generated in the folder where you saved your au3 file. 

if you try open this .exe, you would see some encrypted data that will not be readable. 

7) How to call the generated autoit_ie.exe file in java-selenium. 

  public void getCredentialsFromAutoITExe() {
try {
Log.debug("Reading Username and Password from IE AutoIT exe file");
                                 System.out.println("Reading Username and Password from IE AutoIT exe file");
Log.debug("Read Username and Password from AutoIT exe file");
}catch(Exception e) {
Assert.fail("failed to Read Username and Password from AutoIT exe file");
System.out.println("failed to read credentials from AutoIT exe file"+" "+e);

 public void getAppManagementURL() {

Log.debug("Authenticating to sadakar.selenium.com URL");
                  Log.debug("Authenticated to Application URL and opened the site                             

7) When you run your project (in my case its a maven-java-selenium-junit-cucumber) the pop-up should read the username and password from the auto_it.exe file and fill the corresponding values as shown in below image.

Runtime.getRuntime().exec("auto it exe file path") should be called before driver.get("URL")

Thank you, for stopping by and I hope it helps someone in the community.