Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Master airtest automated testing tools in one article

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

I wrote an article about airtest before. The link is here at https://blog.51cto.com/xqtesting/2420165.

This is the student's original article is also about airtest, dedicated to you, the final copyright of this article belongs to the student Binyu

First, a brief introduction to Airtest

For testers. Mini Program test must be followed and verified after launch. The project where the editor works has now completed the construction of UI automatic testing and monitoring of the APP/ WeChat Mini Programs channel. The following explains how to use airtest to achieve channel monitoring of Mini Program.

Description:

Airtest is an automated UI testing tool based on image recognition and poco control recognition produced by NetEase. The framework of Airtest is an image recognition framework developed by NetEase's team. Computer users do not need to write code line by line, but use screen capture to combine the program into an artifact with intercepted graphics, which is part of Airtest. The editor is based on it to do the secondary development to achieve the function of automatic testing and monitoring alarm.

Git address:

Https://github.com/AirtestProject/Airtest

Second, about automated testing

Meaning: save manpower, material resources, time and hardware resources, improve testing efficiency, especially for tedious and repetitive test cases, can make testers pay more attention to the establishment and development of new test modules, so as to improve test coverage.

Common UI automated testing tools on the market and their advantages and disadvantages:

Compared with the above tools, Airtest has the following advantages and disadvantages:

Third, the construction of the environment

AirtestIDE has integrated all your environments, with its own recording script bar, automatic script generation, and its own editor and simulator, so that you can easily record scripts with an AirtestIDE. The download address is Airtest's website:

Http://airtest.netease.com/

The tutorials and documentation for using AirtestIDE are also available in the following link:

Http://airtest.netease.com/docs/docs_AirtestIDE-zh_CN/index.html

1. Enter the official website: http://airtest.netease.com/, download airtest, decompress it, and click exe to start it.

2. Connect the mobile phone:

Http://airtest.netease.com/docs/cn/2_device_connection/1_android_phone_connection.html

Http://airtest.netease.com/docs/cn/2_device_connection/2_android_faq.html

Different mobile phones may be slightly different. The core is to open the developer mode of the phone and open USB for debugging.

Airtest connects your device to your computer through adb, and then connects to the Airtest framework to complete recording and script running.

The adb path called by the Airtest framework is: {Airtest installation path} airtestcoreandroidstaticadbwindows

Before using AirtestIDE to connect to the device, verify that the device is connected through the adb devices command.

When the real machine can be successfully accessed, the real device will be automatically identified in the device window.

When connecting to the simulator, you can connect the simulator's device connection code in the remote device connection options, or you can identify it after the adb connection is complete.

Note: you need to check the Use javacap option to refer to the official documentation:

Http://airtest.netease.com/docs/cn/2_device_connection/3_emulator_connection.html

IV. Easy to use

Just follow the official documents. The main functions used are recording, touch, sleep, assert_exists and other functions.

V. Mini Program Automation Environment configuration

General input debugx5.qq.com can turn on the debugging function. But if the following problems arise:

Then you need to enter the command

Debugmm.qq.com/?forcex5=true

The results are as follows:

Debugtbs.qq.com

The effect after clicking is as follows: note that the "kernel is not disabled" option is on.

Finally, you can click debugx5.qq.com

Checking will allow you to restart Wechat.

Summary:

If you suddenly find that you can't recognize the elements in Mini Program, repeat the above command:

Debugmm.qq.com/?forcex5=true

Debugtbs.qq.com

Debugx5.qq.com

6. Python runs air script

Airtest script is based on python language. It is officially recommended to use python to run the script.

Install and deploy the python environment

It is recommended to install python3.5 or above and configure the environment

Installation of Python prerequisites

Pip install airtest

Pip install pocoui

Then download a Python editor to edit the code, which is personally recommended to use pycharm. The next step is to use the official launch demo.

Code:

From airtest.core.api import * # connects the local Android device connect_device ("Android:///") # through ADB to install the software under test, apk, path information. Install ("path/to/your/apk") # starts running appstart_app ("com.pingan.certicationApp") # Click on a picture, which is based on the image recognition syntax in Airtest, and the picture is provided by itself. Touch (Template ("image_of_a_button.png")) # Slide voice, the beginning image and the ending image swipe (Template ("slide_start.png"), Template ("slide_end.png")) # add the asserted image assert_exists (Template ("success.png")) # Click the return key on Android # keyevent ("BACK") # Click the Home button on Android to return # home () # uninstall ("package_name_of_your_apk")

7. Detailed explanation of the frame code

The script is as follows:

Multiple case can be run at the same time to generate aggregate report.

Different devices run the same script

The AllReportStartCMD.py file executes the cmd command through python

After running the file AllReportStartCMD.py, you get a report:

As for how to integrate with jenkins, it's very simple. Just write the AllReportStartCMD.py file into the jenkins task.

After that, you can see the results by building.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report