AutoIT

Running AutoIT Executable in Selenium WebDriver

Web applications do not always confine themselves to working entirely on the web. Sometimes they need to interact with the desktop to do things like upload files.

Automating these sorts of workflows are tricky in Selenium. Selenium is confined to automating browsers, so desktop windows are out of scope.

If you are looking to automate workflows that go from browser to desktop and back in Selenium, then a little AutoIT is in order.

AutoIt is a tool for desktop automation. Using AutoIT, you can write scripts for automating desktop-based application and convert them in to an executable file.

The first step is to make automate that desktop-based window in AutoIT and make an executable file. The exact substance of the file depends on your project, but it is a pretty straight-forward task in AutoIT.

The second step is to invoke that executable at run time. Use the following method to invoke the executable from Selenium.

import java.io.IOException;
 import java.lang.Runtime;
 //Method to execute an exe file
 public void executeScript(String scriptPath) throws IOException
 {
 //scriptPath is the path of the executable
 Runtime.getRuntime().exec(scriptPath);
 }

As soon as you invoke this method, all the recorded steps in the executable will be executed and the desktop based window will be automated.

Some disadvantages of using the AutoIT executable are following-

  1. These scripts are window resolution dependent, so it may fail sometime.
  2. In case of uploading a file, if the uploading is taking more time due to some server/internet error, the scripts may not be able to fulfill the purpose.

To solve the first problem, you can use object information of the controls and window so you won’t have to depend on screen resolution.

To solve the second problem, you can specify the timeout period using the winwaitactive function which will give you definite results regardless of server or Internet errors.

Using predefined or user-defined AutoIT functions will make your Selenium scripts more consistent.

The post Running AutoIT Executable in Selenium WebDriver appeared first on OptimusQA.