Ultra-simple automated testing tool without programming: Airtest Getting Started Tutorial

Table of contents

1. Background

2. What is Airtest

3. Download and install Airtest

4. Airtest Getting Started Tutorial

4.1 Connecting devices:

4.2 Specific test scenarios:

V. Summary

1. Background

Many students who have just entered the industry or switched from other industries to do testing are exhausted and numb after doing some work day after day. They feel that there is not much difference between doing testing and screwing in a factory. I also want to do automated testing, but I feel a headache when I look at the code. I chose to do testing because I didn't like programming. Or because of switching from other industries, the interlacing is like a mountain, and programming is too painful.

So today I will introduce to you a tool that can easily write automated test scripts without programming knowledge: Airtest, which will take you out of the sea of ​​suffering as soon as possible! Those who like it, don't forget to follow and like it!

2. What is Airtest

Airtest is a cross-platform UI automation testing framework based on image recognition, suitable for games and apps, and supports Windows, Mac, Android and iOS platforms.

Official website address: http://airtest.netease.com/
Official document: https://airtest.doc.io.netease.com/

In addition to the Airtest image recognition framework, it also supports the Poco framework. Poco is an automated test framework based on UI control recognition, that is, conventional element positioning and recognition to complete automation. Currently, it supports platforms such as Android native, iOS native, Unity3D, cocos2dx, UE4, and Egret, and can also be used in other engines by accessing poco-sdk.

Although this capability is provided, there are two general disadvantages in the element positioning method: element position identification & maintenance costs are high, and code writing efficiency is not high. And if you really need to use the UI control identification scheme for automation, there is Selenium on the web, Appium on the mobile, and Pywinauto on the PC desktop.

Therefore, the protagonist of this article is still Airtest, which has low learning cost and fast writing scripts. It can quickly complete a large number of test scripts without programming code knowledge. In addition, when conventional UI automation cannot or is difficult to identify positioning elements, the characteristics of Airtest image recognition can also be used to solve the problem of automated testing.

Finally, Airtest is based on Python, and all scripts written are Python codes. In addition to entry-level use, Python can also be used for further expansion and secondary development, which is very friendly to test development students.

3. Download and install Airtest

Enter the official website, Windows 64-bit system directly click the download button to download the WINDOWS (64BIT) version:


If it is a Mac, you can click "Other Platform Versions" to download the Mac version:


After downloading, the pure green version does not need to be installed, just unzip the file directly, find AirtestIDE.exe in the unzipped folder, and run it:

You can click "Skip" to skip the step of registering and logging in, and you can use it normally without logging in. After entering, the page is as follows:

4. Airtest Getting Started Tutorial

4.1 Connecting devices:

1. Let's take the automated testing of QQ Music as an example, first start QQ Music. Then go back to Airtest IDE, create a new one, click the "Window" menu, check "Devices", and click the connection desktop icon of "Windows Window Connection", as shown in the figure below:

2. After the connection is successful, you will find that the buttons under the "Airtest Auxiliary Window" on the left have become clickable. When the mouse hovers over the corresponding button, the parameter usage instructions of the button will be displayed, as shown in the figure below:

3. Then click the "+" sign in the menu bar, create a new ".air Airtest project", enter the project name, and the IDE will automatically import the package initialization script, as shown below:

4. Switch to the QQ Music window at this time, and then reduce the size of the Airtest IDE window, so that you can use the function buttons below the "Airtest" auxiliary window to capture pictures of the corresponding operations on QQ Music:


5. The next step is very simple. Use the various functions under the "Airtest" auxiliary window to quickly realize the scene you want to test. Airtest common button description:

touch:点击操作
text: 输入文本操作
sleep:睡眠操作,单位是秒
exists: 是否存在,返回true or false,用于编写逻辑判断代码时使用
assert_exists: 断言是否存在,用于测试断言使用
snapshot:截屏并保存为文件

4.2 Specific test scenarios:

For example, the test requirement is: search for the specified song: Lonely Brave, and select Eason Chan's version to play. Let's take a look at the final effect achieved with airtest:

airtest automated test example

Let's look at the detailed implementation steps:

1. The first step is: click the search box. Click the touch button in the Airtest IDE, and select the picture in the QQ music search box. After selecting the picture, you can see that the script in the IDE has been generated:

2. Step 2: Enter the song name "Lonely Brave" and execute the search operation. In this step, directly click the "text" button in the Airtest IDE, enter the text "Lonely Brave" in the pop-up window, and the script will be generated:

After entering the text, click the search icon to perform a search:

3. Step 3: Click on Eason Chan's version of the Lonely Brave to play. Touch the box to select the picture:

But touch is just a mouse click, how to achieve the double-click effect? Move the mouse on the touch, you can see that it has a times function, the default is 1 click, we set times to 2:

The actual effect is that the double-click effect is not triggered, so one solution is: the play button will appear after one click, and we click the play button again.
Another solution is: use another function double_click, which will trigger the double-click effect:

Note: Since there are many versions of the "Lonely Brave" song found in the search, there are many other versions of the "Lonely Brave" song pictures that are similar to the pictures we intercepted. The default threshold for airtest image recognition is 0.7, that is, a 70% match is considered a match.

Therefore, if you occasionally click on other versions of the "Lonely Brave" song, you can double-click the picture in the Airtest IDE, set the recognition and matching threshold of the picture to 0.9, and increase it to 90% to match, which can solve the problem this problem:

V. Summary

At this point, the script is written. Summarize the test steps:
1. Click the QQ music search box
2. Enter the song name: Lonely Brave
3. Click the search button
4. Double-click Eason Chan's version of Lonely Brave to play music

The corresponding Airtest script is as follows:


Conclusion: What you see is what you get, you only need to follow your test steps, select the corresponding picture with the mouse to record it again, and then the automatic test effect can be realized. The whole process is easy to understand, and no programming knowledge is required. My mother no longer has to worry that I can't do automated testing because I don't know how to program. Hurry to try it!

Of course, some automated testing scenarios in actual work are much more complicated than the above scenario, so as an excellent automated testing software, it is natural to have the ability to deal with more complex scenarios. This article is just an introductory article, let students who have not used it get started first


If the article is helpful to you, remember to like, bookmark, and add attention. I will share some dry goods from time to time...

END Supporting Learning Resources Sharing

Finally:  In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free 【保证100%免费】

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

insert image description here

How to obtain the full set of information:

Guess you like

Origin blog.csdn.net/IT_LanTian/article/details/131228157