Tuesday 2 December 2014

Handle Authentication Window using AutoIT and Sikuli

We can handle authentication window using:
1. AutoIT
2. Sikuli

AutoIT: Download AutoIT from http://www.autoitscript.com/site/autoit/downloads/
Once you install AutoIT in system. Write a autoit script to handle the authentication window.
WinWaitActive("Windows Security")
Send("username")
Send("{TAB}")
Send("password")
Send("{ENTER}")
Save this file as “auth.au3"
Right click on the file and chose “Compile Script (x86)” option and it will make “auth.exe”
Now write the sample java code to use it
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class WinAuthentication_Autoit {

 public static void main(String[] args) {
  System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"\\IEDriver.exe");
  WebDriver driver = new InternetExplorerDriver();
  driver.get("http://codesorcery.net/old/authentication/secret/");
  try {
   Runtime.getRuntime().exec("E:\\AutoIT\\Auth.exe");
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}


Sikuli: Download Sikuli from https://launchpad.net/sikuli/+download
Once you install Sikuli in system. Write a below script to handle the authentication window.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;


public class WinAuthentication_Sikuli {

 public static void main(String[] args) throws FindFailed, InterruptedException {
  Screen screen = new Screen();
  System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"\\IEDriver.exe");
  WebDriver driver = new InternetExplorerDriver();
  driver.get("http://codesorcery.net/old/authentication/secret/");
  screen.type("D:\\Authentication_Username.png"),"username");
  screen.type("D:\\Authentication_Password.png","password");
  screen.click("D:\\Authentication_OK.png");
 }

}

Below are the images used in script:




No comments:

Post a Comment