Short AutoIt Tutorial With Selenium Automation

Selenium works best for web component automation but cannot handle windows native dialogs like Windows Alert popup, Upload/Download dialogs, Authentication dialogs. Most Web Applications uses such dialogs and for a full automation flow we need to be able to handle all such objects.
AutoIt and Sikuli are two open-source tools which can be used to automate such Windows dialogs.
In this post, we will see a small AutoIt example used with Selenium Automation framework to help us get started with AutoIt.

Brief about AutoIt:
AutoIt is a free tool and which can automate windows GUI components, buttons & forms, mouse movements & keystrokes. It also has a recording facility which can generate the scripts we use in our tests. AutoIt comes with a customised "lite" version of editor(SciTe) that makes editing scripts easy with Syntax Highlighting and a Compile option. The Compile option is of great help as we need to use only the ".exe" file from our Selenium code.

What are we testing:
Before moving on ahead, let us see where we will be using AutoIt or the test steps.
We will go to Selenium downloads page and then click previous releases. In there we will select a file which is "deprecated" e.g. While we click to download the zip file there will be a pop-up confirmation message, which we will automate to click with AutoIt.

1. Download AutoIt and Install:
For installation of AutoIt, go to AutoIt downloads page, and download the "AutoIt Full Installation" Software. Once downloaded, follow the installation steps to install the software in your windows box.
After installation you can see as below screenshot in your Windows Start. My box is 64-bit Windows 7 and during installation I have selected default x86 configuration.

2. Before Writing the AutoIt script:
For writing an AutoIt script its better to learn a bit about the scripting language mainly the commands. Its supposed to be BASIC-like scripting language and easy to learn. Help yourself :) Note that we can open the "AutoIt Help File" for reference, it is available at Windows Start->All Programs->AutoIt v3->AutoIt Help File.
In our test we are supposed to do a click on one of the buttons(OK, Cancel) of the popup dialog. So we will use a ControlClick() command. Refer the Help file for the command.
To be on a safer side, we also would like to wait for the pop-up to appear before we do a click, so we will use WinWaitActive() command. From the help file it says that WinWaitActive returns a handle to the requested window on success. The same window handle we can pass onto the ControlClick command.
WinWaitActive takes "title" as mandatory parameter, "text" and "timeout" as optional.
The ControlClick command also takes other mandatory parameters - ("title", "text", controlID). To identify these parameters/args we can use the "AutoIt Window Info(x64)" tool.
Open the tool and our pop-up dialog as seen in screenshot below. Click the "Finder Tool" and drag mouse over the "Cancel" button on the pop-up dialog. We can see all the required inputs for our ControlClick command in the "AutoIt Window Info" tool.

3. Write and Compile the AutoIt script to generate the ".exe" file:
Open the SciTE Script Editor(Windows Start->All Programs->AutoIt v3->SciTE Script Editor) and write down the below code for clicking the "Cancel" button in our pop-up dialog.
Save the file with ".au3" extension in some folder. In my case "checkAuto.au3"
To Compile the script stay in the editor and press Ctrl+F7 or select Tools->Compile. This will generate the ".exe" file in the same folder and with the same filename, here "checkAuto.exe" is generated.
We are done with the AutoIt part, next lets put this script in our Selenium automation.

4. Using AutoIt in Selenium:
Here we just need to call the ".exe" from our test method using Java code:

Below is a sample test method for our test, calling the AutoIt script generated above.
 public void checkAutoIt() throws InterruptedException, IOException {
 driver.findElement(By.linkText("previous releases")).click();

Thats it for a starter on AutoIt!
Next we will try to add more AutoIt script for basic operations like download operation in IE9.

No comments:

Post a Comment