当前位置:网站首页>Airtest solves the problem that a password needs to be entered in the process of "automatic packaging" (the same applies to random bullet frame processing)
Airtest solves the problem that a password needs to be entered in the process of "automatic packaging" (the same applies to random bullet frame processing)
2022-07-25 21:01:00 【The elegance of testing】
Preface
I saw it two days ago Airtest It was raised in the discussion group that 1 An interesting question : A classmate is in Test automatic packaging In the process of , Discovery image oppo、vivo The mobile phone of this kind of brand needs to input the account password in the packing process , And that's going to make install() Instruction failed to run .
It's worth thinking about , How can we ensure that in the process of installing the application , At the same time, complete the task of inputting the account password without interrupting the task of installing the application ?
Use multithreading to solve the problem of
Enter the password
See here , I believe many students have thought of using multithreading to solve this problem . you 're right , utilize python Multithreading can really help us to implement simultaneously Run multiple tasks .
About new threads , We need to use python From the standard library threading modular :
from threading import Thread
# newly build 1 New threads
# among function For thread function ,args Is the parameter passed to the thread function , It has to be tuple type
t1 = threading.Thread(function, args)
# Start thread activity
t1.start()
# Set the thread as a guardian thread
After a brief understanding of python Some basic uses of threads , Let's go back to the question , Before performing the task of installing the application , We can turn on 1 Threads , It is used to wait for the pop-up of the password pop-up window , And enter your account and password 、 Click Install and so on :

The complete example code is as follows :
PS: thank Airtest user “jxou” The above solutions are provided .
Extended reading : Learn how to use Python Of threading modular 、 Master the foundation of concurrent programming
Knowledge development
1.install() And uninstall()
install() And uninstall() All are Airtest At the heart of API, for Install and uninstall apps , And they all Only Android platforms are supported :
install(filename) , among filename Path for the installed application
uninstall(package), among package Package name of the application to be unloaded
Example :
from airtest.core.api import *
install(r"D:\demo\tutorial-blackjack-release-signed.apk")
uninstall("org.cocos2dx.javascript")
2.install_app() And uninstall_app()
stay airtest Android module of Next , It also provides ways to install and uninstall applications , Namely install_app() and uninstall_app() .
Compared with install() Method ,install_app(filename,replace=False,install_options=[]) The parameters of the :
filepath ,apk The file in PC The complete path on
replace , If the application already exists , Whether to replace , The default is False
install_options ,install Additional options for the command , The default is [], Fill in “-l”、“-t”、“-s”、“-d" and ”-g" Equal parameter , be used for Control installation apk act
among ,install_options The meanings of the parameters of are as follows :
“-l” , Install the app to the protected Directory /mnt/asec
“-t” , Allow to install AndroidManifest.xml in application Appoint android:testOnly="true" Application
“-s” , Install the app to sdcard
“-d” , Allow demotion to override installation
“-g” , Grant all runtime permissions
Example :
from airtest.core.android.android import *
android = Android()
# Non overlay installation
android.install_app(r"D:\demo\tutorial-blackjack-release-signed.apk",False)
# Overlay installation
android.install_app(r"D:\demo\tutorial-blackjack-release-signed.apk",True)
android.uninstall("org.cocos2dx.javascript")
In addition, under the Android module , Some other application related methods are also provided :
list_app(third_only=False) , return packages list ,third_only If True , Return only the list of all third party applications
path_app(package) , Print out package Full path to
check_app(package) , Check package Whether there is... In the device
In the actual test application , For example, we need to install an application into a device , You can use it first check_app(package) Check if the app is installed on the current device , And then decide whether to install directly or overlay :
from airtest.core.android.android import *
android = Android()
try:
android.check_app("org.cocos2dx.javascript")
print(" The current device already has applications to install , Perform overlay installation ")
android.install_app(r"D:\demo\tutorial-blackjack-release-signed.apk",True)
except AirtestError:
print(" There are no applications to be installed in the current device , Perform a non overlay installation ")
android.install_app(r"D:\demo\tutorial-blackjack-release-signed.apk",False)
3.start_app()、stop_app() And clear_app()
Other commonly used methods for application operations are start_app() 、stop_app() And clear_app():
start_app() , Start the target application on the device , Apply to Android and iOS platform
stop_app() , Terminate the operation of the target application on the device , Apply to Android and iOS platform
clear_app() , Clean up the target application data on the device , Only applicable to Android platform
Summary
Today, I mainly share with you how to use multithreading to solve the problem of inputting account and password in the process of automatic package loading , In addition, I have added some airtest The method of application operation , Here's a freshly organized mind map , If you need it, you can save it for later check :

Last : It can be in the official account : Sad spicy bar ! Get one by yourself 216 Page software testing engineer interview guide document information 【 Free of charge 】. And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
Now I invite you to join our software testing learning exchange group :【746506216】, remarks “ The group of ”, We can discuss communication software testing together , Learn software testing together 、 Interview and other aspects of software testing , There will also be free live classes , Gain more testing skills , Let's advance together Python automated testing / Test Development , On the road to high pay .
Friends who like software testing , If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One Key triple connection !
Software Test Engineer self-study tutorial :
Interface performance test — Software testers will 618 Analysis of actual combat scenes
Jmeter Explain the case in practice — Software testers will

边栏推荐
- Basic knowledge of Marine Geology
- How to use buffer queue to realize high concurrent order business (glory Collection Edition)
- IEC61131 address representation
- leetcode-6130:设计数字容器系统
- 预处理指令
- Decompile app
- An interview question about concurrent reading and writing of map in golang
- An interview question about interface and implementation in golang
- Niuke-top101-bm38
- MySQL master-slave replication data synchronization, summary of common problems
猜你喜欢

两数,三数之和

Step num problem

leetcode-155:最小栈

结构体,枚举类型与联合体

Opencv learning Fourier transform experience and line direction Fourier transform code

Leetcode-6130: designing digital container systems

Unity VS—— VS中默认调试为启动而不是附加到Unity调试

Illustration leetcode - 3. longest substring without repeated characters (difficulty: medium)

leetcode-114:二叉树展开为链表

Focus on data | Haitai Fangyuan directly hits the construction idea of data security governance in the securities industry
随机推荐
leetcode-6129:全 0 子数组的数目
Jmeter分布式压测
leetcode-114:二叉树展开为链表
Google guava is just a brother. What is the real king of caching? (glory Collection Edition)
Canvas 填充渐变
In June 2021, the interview suffered a Waterloo. Is it so convoluted now
preprocessor directives
The role of the resize function is "suggestions collection"
LeetCode刷题——猜数字大小II#375#Medium
Yolov7 training error indexerror: list index out of range
How to automatically generate short chains? How to generate links with UTM parameters online in batches?
[online tutorial] iptables official tutorial -- learning notes 2
The international summit osdi included Taobao system papers for the first time, and end cloud collaborative intelligence was recommended by the keynote speech of the conference
NPM module removal_ [solved] after NPM uninstalls the module, the module is not removed from package.json [easy to understand]
使用oap切面导致controller被重复调用
Sum of two numbers and three numbers
ES6 --- four powerful operators (?,? =,?.,?:)
resize函数的作用「建议收藏」
Leetcode-6130: designing digital container systems
leetcode-146:LRU 缓存
