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

How to use wool in Airtest video clips

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

How to use Airtest wool short video, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

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. The ancestor of this framework is a novel graphical scripting language Sikuli. The principle of the Sikuli framework is that computer users do not need to write code line by line, but use screenshots to combine the captured graphics into an artifact program, which is part of Airtest.

   in addition, Airtest is also based on the poco U control search framework, this framework is also NetEase's own cross-platform U test framework, the principle is similar to appium, through the name of the control, id and so on to locate the target control, and then call function methods, such as click (), swip () and other methods to click on or operate on the target control.

I use Airtest instead of appium mainly because the Airtest environment is very convenient to build, basically after installation all the necessary tools are integrated, including python and adb,Airtest in Python and native Python is not the same, so to run on the machine also need to install the Python library: pip install poco. Because Airtest was developed by NetEase, it has friendly documentation and tutorials.

Official document

Airtest Quick start tutorial

Airtest-ide tutorial

Airtest tutorial

An example to be written this time is a simple example of gold coin earned in Douyin Express Edition, which is very simple, mainly to use Airtest.

Install Airtest

Https://airtest.netease.com/

Download the installation package for the corresponding platform, and start normally after installation.

Connect to the Android simulator

Open Airtest, click Refresh ADB on the right, and the machine that is connected to the computer will appear (be sure to turn on USB debug mode). If not, restart ADB and refresh. After the connection machine appears, three options appear in the drop-down list after connect: Use javacap, Use ADB orientation, and Use ADB touch. In order to avoid inexplicable problems, it is best to select all of them, and then click on the connect connection to show the system desktop.

In the process of execution, Airtest will install several software to the phone: Yosemite (an input method that mainly executes input text) and pocoservice-debug (execute the command sent by Airtest). In the process of connecting to the real phone, an error Failure [INSTALL_FAILED_OLDER_SDK] is reported. The mobile phone version is too low to install data packets. I have an antique machine, which is stored in 512, and the Android version is 4.3, so be sure to pay attention to the Android version when testing.

Write code

We don't mainly talk about the Airtest tutorial in this article, so we won't explain it in detail. Here I recommend a very good learning website-bilibili, which is this two-dimensional programming website. There are many detailed video tutorials above. Take an hour to take a look at them and then go through the official tutorials. Let's give a brief explanation with the example code.

The code is as follows:

From airtest.core.api import *

From airtest.cli.parser import cli_setup

From poco.drivers.android.uiautomation import AndroidUiautomationPoco

Class DouYin:

Def _ init__ (self):

If not cli_setup ():

Auto_setup (_ _ file__, logdir=True, devices= [

"Android://127.0.0.1:5037/emulator-5554?cap_method=JAVACAP&&ori_method=ADBORI&&touch_method=ADBTOUCH"

])

Self.poco = AndroidUiautomationPoco (use_airtest_input=True, screenshot_each_action=False)

Size = self.poco.get_screen_size ()

Self.width = size [0]

Self.height = size [1]

Def VisitHome (self):

Self.poco (text= "Douyin Express"). Click ()

# after entering the short video page, find out whether the recommended element exists

Self.poco (name='com.ss.android.ugc.aweme.lite:id/amh'). Wait (30)

# finding the recommended element indicates that you have entered the home page, but it will take some time for the video to load. Wait 5 seconds here.

Sleep (5)

Try:

# Adolescent mode option may appear when you open it for the first time

Self.poco (text=' I know'). Click ()

Except:

Pass

Def LoopMove (self):

Start_pos = (0.5 * self.width, 0.8 * self.height)

End_pos = (0.5 * self.width, 0.2 * self.height)

While True:

# slide from the bottom to the top and switch the video

Swipe (start_pos, end_pos, duration=1)

# watch each video for 20 seconds

Sleep (20)

If _ _ name__ = ='_ _ main__':

Douyin = DouYin ()

Douyin.VisitHome ()

Douyin.LoopMove ()

When running using the py script, if you are a user of Linux or macOS, please pay attention to whether there is an error in the running result, indicating that adb does not have the permission to run.

The official documents have already given us a hint.

Cd / Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/airtest/core/android/static/adb/mac

Chmod + x adb

Mainly the configuration of connected devices in auto_setup, as explained in the official document

We have added parameter settings cap_method, ori_method and touch_method in the connection, which correspond to the three options on the tool. If you do not set the connection, there will be problems.

Get_screen_size gets the screen size so that the sliding distance is the same for different devices and resolutions.

Poco (text= "Douyin Express"). Click () search for the "Douyin Express" element on the screen and click Open. Make sure that Douyin is displayed on the home page, and slide if it is not on the home page.

It takes time for sleep (5) video to load, so let's wait 5 seconds here.

Swipe (start_pos, end_pos, duration=1) performs sliding operations, setting start and end points and sliding time

Then you can do all kinds of short videos all the time. Of course, after installing APP, it would be better to manually open and log in the software, so that we don't need to do these steps in our automation.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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