Be on the same page with us
Subscribe to our latest news
By clicking the button Subscribe you give a permission for the automatic sending of e-mails
Automated testing for mobile games' UI with Airtest IDE. Tutorial
There is a huge interest in mobile games test automation according to the requests that we are currently getting from the market. Let's try to find out how is it done using the free open-source tool Airtest.
September 11, 2020
In the recent decade, we noticed a huge adaptation of test automation techniques in the agile software development process. It would not be an exaggeration to say that test automation allows us to deliver new functionality much faster with high-quality standards.

We are pretty familiar with such open-source automation solutions as Selenium and Appium that cover web and mobile applications testing. Both frameworks support the WebDriver interface that unifies approaches of test automation between multiple platforms like iOS, Android, or just a web application. In most scenarios test automation may be divided into 3 major parts:

  • Implementation of Page objects - classes that describe elements on the page or mobile view along with locators (XPath, ID, CSS, etc.)

  • Implementations of tests - they interact with your application through page objects performing additional validations

  • Preparation of test data sets that will be provided into your tests as arguments
These simple steps make your tests automation more flexible for application changes. You can easily adjust tests in response to frequent UI elements updates even when tens of page objects are used in automation scripts. Test data externalization makes your automation data-driven so that you are capable to verify hundreds of different scenarios just using external XLS or DB provides for the same test script.

There is a huge interest in mobile games test automation according to the requests that we are currently getting from the market. Let's try to find out how is it done using the free open-source tool Airtest.
Framework overview
Airtest is known as a cross-platform UI automation IDE that allows you to automate mobile games, Windows, Android, and iOS applications. In the article, we will concentrate on game automation. Airtest supports both black-box and white-box approaches. Choosing the first approach we interact with the application through UI (screenshots of particular elements), while the second one requires an integration of POCO SDK into our game sources. Using POCO you are capable to interact with application controls through more accurate locators like IDs making the automation process less flaky. POCO supports the following engines out of the box:

  • Unity3D
  • Android native apps
  • OSX apps
  • Windows apps
  • cocos2dx-lua
  • cocos2dx-js
  • Egret
  • NetEase
  • Internal Engines
Demo application
For demo purposes, we have chosen a simple Android mobile game Happy Hygiene. The game is built on the top of the Unity3d engine and available on Google Play. Let's begin our black-box testing!
AirtestIDE provides two versions of Windows and macOS clients. Just download the installer from the official websites and unzip it. Connect an Android device to your computer and allow USB debugging using ADB. AirtestIDE relies on ADB to communicate with Android devices.

Next, open the AirtestIDE and follow the steps below to connect the device:

  1. Turn on the USB debugging option in Settings - Developers Options - USB debugging, for more details refer to the official Android documentation.
  2. In the AirtestIDE devices panel, click the Refresh ADB button to see the connected phones.
  3. If there is no device connected, try to Restart ADB. If it still fails, refer to FAQ.
  4. Click next to the corresponding device on the Connect button to connect the device withAirtestIDE.
Automation sample
Under black-box testing, we understand interaction with an application via its UI interface only. Airtest provides the image recognition mechanism for that purpose. Literally we have to capture a set of screen fragments that represent different controls and combine multiple actions to emulate user experience.

Airtest IDE is super intuitive for new users, the main screen may be divided into 4 main areas:
  • Main controls - main actions related to script execution
  • Actions - what you can do with your test app
  • Script - in most cases it shows the result of generated code
  • Device screen - the area where you capture UI elements
We would like to automate the following simple script:

  1. Press first level in the main menu
  2. Tap to start
  3. Capture screenshot for reporting
  4. Verify that we have 5 lives by default
  5. Press pause button
  6. Verify that game is paused
Let's click on the first button in the main menu. Press touch and crop screen area with the button. You will see the generated script in the middle area:
Now we wait for the intro screen and tap on the start button, in that case we are using touch and wait actions cropping appropriate areas for interaction and validation:
When the game is started we are going to take a snapshot. Then we verify that 5 lives are shown using assert_exists operator. Finally, we touch the pause button and assert_exists that the pause label is displayed:
Make sure that you write correct comments in snapshots and validation comments so that it would be easy to analyze test failure if something goes wrong. Now we are ready to run our first script, just press play button in the top:
Works like a charm! From the top control bar you can open an automation report that consists of all the script actions and validations, along with screenshots for better automation results analysis:
Let's hope this helped to learn more about games' UI test automation or AirtestIDE. In the next article, we will discuss how to use Airtest in the white-box mode, along with integrating POCO SDK into application sources. Stay tuned!