Steps to run AutoIT Script as a Pre-run executable to handle Windows Security Authentication or Integrated Windows Authentication dialog (IWA)
The example connects to a publicly accessible site https://the-internet.herokuapp.com/ that uses basic authentication.
a) Download and Install AutoIt on your local Windows machine (required)
Source: https://www.autoitscript.com/site/autoit/downloads/
NOTE: The 64bit version of AutoIT works on IE11, and not on IE9. The 32bit version works with both browser versions.
b) Identify Window title via “AutoIt Window Information Tool” (optional)
Source: https://www.autoitscript.com/autoit3/docs/intro/au3spy.htm
c) Write a script <scriptname>.au3
WinWaitActive("Windows Security")
Send("admin")
Send("{TAB}")
Send("admin")
Send("{ENTER}")
d) Verify if au3 script is valid; We found SciTE a helpful editor created by AutoIT team
Source: https://www.autoitscript.com/site/autoit-script-editor/
Programming and writing scripts in Notepad can be a pain. The AutoIt team has created a custom version of SciTe that has the following features and tools included:
- Syntax highlighting and code completion
- Code prettifier
- Syntax checker
- And much much more…
The homepage for the AutoIt version of SciTe can be found here.
e) Compile script generating <scriptname>.exe
f) Reference the script as part of Prerun capability using “either” of the two options below
Upload script to a publicly accessible link; example http://url.to/your/<scriptname>.exe
OR
Upload script to sauce storage using Sauce REST API call as documented here: https://docs.saucelabs.com/mobile-apps/app-storage/
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" --location \
--request POST 'https://api.us-west-1.saucelabs.com/v1/storage/upload' \
--form 'payload=@"<path/to/your/file>"' \
--form 'name="<filename.ext>"'
g)Simple Java Example:
public static void main(String[] args) throws Exception {
public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.us-west-1.saucelabs.com:443/wd/hub";
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("platform", "Windows 7");
caps.setCapability("version", "11.0");
caps.setCapability("seleniumVersion","3.141.0");
caps.setCapability("name", "SampleAutoItSauceSampleWinSec");
//import org.json.JSONObject;
JSONObject jsonObj = new JSONObject();
jsonObj.put("executable", "storage:filename=SampleWinSec.exe");
jsonObj.put("background", true);
//import org.json.JSONArray;
JSONArray arr = new JSONArray();
arr.put("--silent");
arr.put("-a");
arr.put("-q");
jsonObj.put("args", arr);
caps.setCapability("prerun",jsonObj);
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("https://the-internet.herokuapp.com/basic_auth");
driver.quit();
}
Sample script, executable and java test code: https://github.com/raolaks/AutoIT
Additional resource:
https://docs.saucelabs.com/web-apps/automated-testing/selenium/pre-run-executables/
https://www.autoitscript.com/autoit3/docs/intro/au3spy.htm
https://www.autoitscript.com/site/autoit-script-editor/