Performing automation testing with Airtest¶
Airtest in an automation test framework with main focus on mobile games however it can be used for all native Android apps as well. Airtest automation test framework uses image recognition technologies and provides cross-platform APIs that allows among other to install applications, perform simulated input, make assertions, etc.
Airtest integration with AirtestIDE¶
Airtest assistant window is placed on the bottom left side of AirtestIDE GUI layout by default (as shown on screenshot below).
We can divide the buttons into three main groups - operations, assistant funtions and assertions:
These buttons can be easily filtered out using dropdown menu as follows:
Recording Airtest script in AirtestIDE¶
The instructions above can be combined with the Python code, combining Python scripting with predefined set of Airtest instructions, we can easily create a powerful fully automated test script.
There are two ways how to record the Airtest script - manually create screenshots or automatically capture all click actions on the screen and generate the screenshots automatically.
Following demonstrates how to record the script manually:
- select action you want to perform in Airtest window
- to select the object of interest, draw a rectangle on the target object on the screen device, the code will be automatically generated to your script
- repeat the steps for all objects you need to check
Sometimes, creating the screenshots manually is not very effective way, that’s why AirtestIDE also provides automatic recording features. In each step, wherever you click, the IDE will automatically capture the screenshots generated according to the current click area.
Automatic script recording can be turned on by click camera icon in Airtest window. To stop the automatic script recording, press the camera icon again.
Following demonstrates how to record the script automatically:
Running Airtest script and inspecting the report¶
AirtestIDE also provides the features to run/replay the script and inspect the test report which is generated once the script execution is finished. To do so, there are 3 buttons available to manage run script, stop script and inspect the log.
To run the script, perform following steps:
- click the start button (the most left button in the screenshot above)
- or press F5 key shortcut
To stop script, perform following steps:
- click the stop button (the middle button in the screenshot above)
- or press F10 key shortcut
To inspect the log, perform following steps:
- click the log button (the most right button in the screenshot above)
- or press Ctrl+L key combination
Image Editor Feature¶
AirtestIDE provides not only the ability to take the screenshots but also you can edit these captured screenshots using the Image Editor feature to adjust the image recognition parameters such as threshold, target position area and RGB channel to increase or adjust the image matching results.
To invoke the Image Editor dialog, double-click on the picture in script area. Click OK to accept your modification, or click Cancel to abandon it.
We provide a function to preview the matching rate of the screenshot on the current screen. Clicking the
Snapshot Recognition button in the photo editor will capture the current screen of the mobile phone and perform a recognition. If the recognition is successful, the identified area of the screenshot will be marked to make the debugging easier.
At the same time, a right click in the screenshot display area will pop-up a menu where you can choose to take another screenshot of the mobile device, specify the use of a certain type of identification algorithm and other operations.
Following values can be adjusted for each captured screenshot:
threshold (float) - it sets the image matching threshold, the valid values are from interval [0.0, 1.0], the default value is 0.6
target_pos (int) - set the position to operate on image matching result, the valid values for position flag are from interval 1-9
RGB (bool) - set whether to use RGB channel or not when calculating the confidence of image matching result, the default value is False, i.e. use the gray image to calculate the threshold