AutoIt is a free open source tool that can be used to create and automate desktop applications. We like to use AutoIT in a lot of projects here and have even set up some automation for clients.
The following are the steps to quickly create a framework and automate testing a desktop application.
The framework specifies the location of all files. It should also specify the main Driver Script file that will execute all test cases sequentially
In this case, we are going to use the following:
- Test Data Sheet: a sheet that contains test data for test cases.
- Test Result Sheet: a sheet to store test results.
- Main Excel Sheet: a sheet which contain the test cases that we will be automating.
- Test Scripts Folder: a folder that contains all test scripts.
- Library Functions File: a file with pre-defined functions that can be used by any running script.
- Driver Script: a script that runs all other scripts and controls the order in which they run.
Object Identifier Tool (Ctrl+F6)
Once the framework is ready, next step is to identify the test cases which can be automated. This is accomplished using the Object Identifier (AutoIt Window Info) tool.
This tool comes with Object Finder which provides control information when dragged and dropped on any object, like a button or checkbox. The control information for an object consists of following:
- Object Classname
- Advanced (Class)
- Object ID
- Object Handle etc.
We use this information, classname and object ID in particular, in our script to control the behavior (Check, Select etc) of the object.
Script Recorder (Alt + F6)
AutoIt Comes with a very handy utility named Au3 Recorder.
This utility is used to record actions which user performs while working on an application.
It has three main functions:
- Generate Internal functions (Function to activate/set delay for window movement)
- Record Window Text
- Record Mouse Movements
All actions like Mouse clicks and keystrokes are captured along with information of window on which user is working and this information is put together on a editor called Scite.
Scite is a lightweight editor for building programs. Scite provides an IDE for creating scripts using AutoIt.
Some of its main features are:
- Ability to easily handle very large files
- Color coded text based on file type
- Bracket matching
- Highly stable – can easily work day-long multiple window sessions with zero crashes
- Compile/run/debug support
- Extensions support
All utilities provided by AutoIt can be directly opened from Scite that makes it much more useful.
AutoIt Help File
AutoIt comes with a large list of built-in functions and these functions are aggregated together in a file named “AutoIt Help”. It contains a list of basic and advanced functions like :
Automating a Calculator App
Here is how we would go about automating a simple calculator applications:
Right click at the desired location and go to “ New> AutoIt V3 Script ” which will open a blank AutoIt file
Write these steps in the open file and save it
Run("Calc.exe") WinWaitActive("Calculator") WinActive("Calculator") Sleeper() ControlClick("Calculator", "", "Button5", "Left") ;Click the number 1 Sleeper() ControlClick("Calculator", "", "Button11", "Left") ;Click the number 2 Sleeper() ControlClick("Calculator", "", "Button23", "Left") ;Click the + button Sleeper() ControlClick("Calculator", "", "Button16", "Left") ;Click the number 3 Sleeper() ControlClick("Calculator", "", "Button28", "Left") ;Click the Equal button Sleeper() WinClose("Calculator") Func Sleeper() Sleep(1000) EndFunc
Now execute the above file by pressing “F5″ button
Calculator window will open and will do the desired functions and then close by itself after showing the result.
You can download AutoIt and Scite editor from the AutoIT downloads page.