one background

1. Current issues with UI automation

  1. It is difficult to use a set of tools to automate testing on mobile, Web, and desktop

2. The version update page changes greatly, and the maintenance cost of automatic scripts is high

3. Image content is difficult to verify

2. The solution

UI automatic design is carried out by using image recognition method instead of traditional coordinate positioning method

two Introduction to Airtest automation

Airtest is a cross-platform UI automation testing framework based on image recognition principles. The Airtest IDE operation page is shown below

1. advantages

Based on Python and cross-platform, it can be used for mobile, Web, and desktop UI automatic testing, and supports Windows, ios, and Android

2. composition

The whole tool suite consists of Airtest IDE, Airtest, Poco and Airlab

  • Airtest IDE: Cross-platform UI automation editor
  • Airtest: A cross-platform Python UI automation testing framework based on image recognition principles
  • Poco: An automation framework based on UI space search
  • Airlab: netease Airtest cloud test service

3. Environment set up

1. Download and install the AirtestIDE

1.1 Windows users
  • Download the corresponding ZIP package from the official website to obtain the AirtestIDE folder according to the 32-bit or 64-bit version of the system
  • Double-click the AirtestIDE/AirtestIDE exe can start to install, always click next
  • On some machines, you may not be able to start properly due to compatibility problems with the graphics card, or script editing window cannot be edited. You can select a compatibility mode from the new compatibility mode Settings of IDE 1.2.3 and restart the IDE. In this way, the IDE will start in compatibility mode by default in the future
  • Double-click the icon to run

1.2 MacOS user
  • Download the airtestide. DMG file from the official website, double-click to decompress the file, and drag the airtestide. app to the Application folder
  • There may be a flash back problem when you start it for the first time. You can start it again and use it normally

2. Interface is introduced

  • Navigation bar: mainly script file management, and IDE Settings
  • Airtest auxiliary window: you can quickly insert part of the operation code
  • Poco helper window: You can see information such as the native UI structure
  • Selenium window: You can quickly insert parts of the operation code using the same method as the Airtest helper window
  • Script editing window: Where code editing takes place
  • Log view window: you can view all Log information when running the script. You can view information about locating elements or controls
  • Device window: you can view device information and control devices. It can be divided into four parts: mobile device connection, remote device connection, Windows window connection, and ios device connection

3. Connected devices

3.1 the Android connection

1. Open developer options and enable USB debugging

2. Connect through data cable or wifi (turn off mobile assistant)

3. Agree usb debugging on the mobile phone

IOS links refer to official document airtest.doc.io.netease.com/IDEdocs/dev…

3.2 Connecting the Simulator

1. Obtain the IP address and port number of the simulator

2. Enter the IP address and port in adb Connect IP: port format for remote device combos

3. Click Connect

4. Wait a few seconds until the simulator device is displayed in the device list. Click Connect

3.3 Windows Connection

In the device window-Windows connection, click select game screen or search window, select the window to complete the connection

Four. Write and execute use cases

This document uses android phones as an example to write demo cases using the Airtest command

1. Write a script

Operating instructions:

  • Touch: touch
  • Swipe: sliding
  • Wait, wait
  • -Dan: Do they exist
  • The snapshot: screenshots
  • Text: Enter the text
  • Keyevent: buttons
  • Sleep, sleep
  • Assert_exist: The assertion exists
  • Assert_not_exist: The assertion does not exist
  • Assert_equal: Asserts equality
  • Assert_not_equal: The assertion is not equal
1.1 Creating a Script

In the action bar, click File — New Script –.air Airtest project

1.2 Recording Scripts
1.2.1 Automatic Recording Scripts

Click the automatic recording button in the Airtest assistance window to start recording

When you operate in the device screenshot area of the device window on the right, the corresponding action will be automatically recorded as a code, and the picture of the operation area will be automatically captured

You need to manually add a wait or sleep between operations, otherwise you are likely to fail because the operation is out of sync with the display

Automatic image capture is usually not very accurate. Manual image capture is recommended

1.2.2 Manually Recording scripts

Click the operation instruction in Airtest and then go to the screenshot in the connected device window to complete one operation step

2. Execute the script

Click the run button on the menu bar or press F5 to start executing the script

You can also run airtest run “path to your. air dir” –device Android: / / /

Five. Check the report

In the AirtestIDE, you can click the “View report” button at the end of the upper icon menu with Ctrl+L, and then automatically open the report page using the default browser

1 Report Content

The report is divided into two parts:

① In the upper part of the report, you can see some information related to the report, such as the name of the report, author, report description (customizable), overview, and so on. Click on any of the tabs and the test information will be displayed below.

② The second half of the report shows each test action and its execution in detail. Click the test action on the left. Details about the execution result of the corresponding action are displayed on the right. We can also filter different execution results on the right side.

2 Customize the report description

If the following is written in the script, it will show up in the report:

Author Corresponds to the script author

Title Indicates the script title

__desc__ can be written as a long script description, which will be displayed on the page and will collapse automatically if it exceeds a certain number of lines

Three other

Log files can be viewed by clicking log.txt

Click on the step’s eye icon to see the context

Clicking on the thumbnail of the picture shows the execution of the corresponding step

conclusion

Airtest operation is relatively simple, basically does not involve the code, so it is very suitable for beginners who have no test experience to use this tool to do UI automation testing, and Airetest also provides open source API, so that senior test engineers can do advanced customized extension functions based on the framework of Airtest.