Airtest is what?

Simple understanding: UI automatic testing framework based on image recognition

What the layman understands: Automated tests can be done with screenshots

Application scenario: Games, APPS, PC software, Windows, Android, IOS

Airtest official document

Liverpoolfc.tv: airtest.doc.io.netease.com/

Quick learning series: airtest.doc.io.netease.com/tutorial/0_…

AirtestIDE using document: airtest.doc.io.netease.com/IDEdocs/get…

Official blog: juejin.cn/user/127508…

If you know Python, it’s great, because AIrtest scripts allow you to write Python scripts

probably

At present, the blogger business only involves PC software, so this is only about how to automate the testing of PC software

Main application scenarios

  1. Generally used to run some main process, to see if there will be a probability problem
  2. Verify that the occasional problem has been bugfixed
  3. Some repetitive operations are involved

Connect Window

  • To select the desktop, select the desktop mode instead of using “Select Window” to select the desktop
  • Select window is recommended, not Search window.

.air script parsing

The.air script file is actually a normal folder with a.py file of the same name attached to it, which must be the same name

Initializing the Environment

 auto_setup(basedir=None, devices=None, logdir=None, project_root=None)
Copy the code

The automatic configuration initializes the runtime environment and attempts to connect to an Android device by default if no device is currently connected.

If auto_setup does not pass in any parameters, Airtest will initialize the environment by reading the parameters passed in from the command line at run time. (i.e. : auto_setup(__file__))

Run the script

Method 1: Run the script on the CLI

Airtest run Untitled. air — Device Device –log Log

Method 2: Run the script by using the AIrtestIDE

AirtestIDE Installation directory Runner air Script directory — Device Device on which scripts are run –log directory to store logs

“E:\AirtestIDE_2019-09-11_py3_win64\AirtestIDE” runner “C:\Users\user\Desktop\airteach.air” –device Windows:///198894 –log “F:/Airtest_logs\d77c305860c92615b15f443398ec3f57”

Device to connect

  • If the device is connected (without –device) while executing the command line, you can use the connect_device interface in your script code to connect to the device. Example: connect_device (” Windows: / / / 198894)”
  • The device() interface retrieves the device currently in use and returns a window handle if it is a window (198894)
  • Airtest allows a script to connect to multiple devices at the same time, using the SET_current interface to switch between multiple devices

Core packages

  • Airtest.core. API cross-platform core package
  • Airtest.core. Android Exclusive package for android platform
  • Airtest.core. ios Exclusive ios platform package
  • Airtest.core. Win Window platform exclusive package

The image class Template is introduced

Template(r”tpl1556019871196.png”, record_pos=(0.204, -0.153), resolution=(1280, 720))

Template is the image class encapsulated by Airtest. The runtime will first read the image, and then find the coordinates that best match the image in the current screen, and finally perform touch click

Parameter 1: name of the image

Parameter 2: record_pos finds no matching image near this position and expands the search scope to the whole screen

Parameter 3: resoution picture resolution. If the script is played back on different devices, Airtest will scale the resolution of the current picture to a certain extent in proportion to facilitate cross-resolution matching of pictures.