The introduction

Airtest is a UI automatic test tool produced by netease based on image recognition and POCO control recognition. An image recognition framework developed by netease team allows computer users to compose magical programs by taking screen shots instead of writing code line by line. In addition, Airtest is also based on the control search framework POCO, which is also netease’s own cross-platform testing framework. The principle is similar to Selenium. Methods such as click(),send_keys() to perform related operations on the target control.

After the development and open source of the Airtest Project solution based on graphical recognition, it effectively lowers the threshold of automated testing and truly improves the testing efficiency. Google says Airtest is one of the most powerful and comprehensive automated testing solutions for Android games.

So, such a good, powerful automation framework, of course we have to learn!

The principle is introduced

Airtest currently integrates the Chrome browser for Web automation testing based on Selenium. Through recorded Python scripts, the Chrome Driver is called to drive the browser to perform specified actions. So through the recorded script you will find that selenium’s syntax is applied. So the principle is shown below:

The installation

AirTest Project official website: Airtest.netease.com/, go to the official website to find the latest version download!

You can download the AirtestIDE without installing it. You can unpack the AirtestIDE folder and get it integrated with all environments. It has its own recording script bar, automatic script generation, editor and simulator, so you can start recording scripts easily.

Interface to know

To activate the AirtestIDE, click airtestide. exe in the AirtestIDE directory.

After launching, select “Window –>Selenium Window” to display Selenium related operation control buttons. The detailed interface is as follows:

The window after opening is as shown in the figure below:

Let’s take a look at the functions of each button:

Open and set up the browser:

This is the browser button that launches a browser controlled by the Selenium driver. Subsequent recording operations can also be performed by operating the launched browser;

When you start your browser, you will be prompted as shown in the image below. Click “Yes” to generate the initialization script.

The script looks like this:

The browser supported by Airttest is Chrome by default, of course other browsers are also supported, but this one is recommended and it should be the best supported, so It is recommended to use Chrome.

Before using Airtest for Automatic Script recording for Chrome, specify the startup path of Chrome and enable the Chrome Driver built in Airtest to match the browser version.

The latest version of Airtest comes with chromeDriver. exe (the self-matching version), which must match the Chrome browser. From the Airtest Setup menu, in selenium options, set the Chrome browser installation path, as shown in the following figure:

This makes it easy to automate Web testing using Chrome.

Open the web page

The start_web button launches the browser and opens the corresponding page. Click the button to generate the following code:

Then change the contents in brackets to the corresponding URL, for example, open the page of “Baidu”, you can modify the following code:

driver.get(“www.baidu.com”)

Then run to start the browser to open the page!

Page other operations

When we do Web automation, we often need to switch the TAB page and return the page, so Airtest also has buttons for such common operations can be directly related to the operation.

As shown below:

Switch to the previous page -previous_tab, click it will automatically generate the following code:

Switch to the next new page -new_tab, click it will automatically generate the following code:

Return to the previous page: back, generating the following code:

Proceed to the next page: Forward, with the following code:

Those with a background in Python automation will notice that the code generated by these operations is pretty much the same as Python code. Here you can directly achieve the corresponding page operations, and do not need to write their own code.

Recording script

Airtest greatly reduces the cost of Web automation because it provides recording capabilities! The following buttons can be associated with our script recording.

Record button, click on the browser operation, the corresponding script will be recorded;



Touch the button: The click action used to record the clicked page element, equivalent to the click action;

Text Text button: script for recording text input operations, equivalent to the send_keys () operation;

Assert button: script used to assert the existence of an element, which when clicked generates the corresponding assertion directly.

The specific operation and script effect and modification of these recording buttons will be explained in the next article. Stay tuned!