当前位置:网站首页>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

边栏推荐
- cv图像翻转,EmguCV图像旋转「建议收藏」
- Interpretation of filter execution sequence source code in sprigboot
- Leetcode skimming -- guess the size of numbers II 375 medium
- Leetcode-155: minimum stack
- An interview question combining defer and function in golang
- ES6---4个强大运算符(??、??=、?.、?:)
- [advanced drawing of single cell] 07. Display of KEGG enrichment results
- [technical dry goods] how to ensure the idempotency of the interface?
- wokerman 自定义写入日志文件
- MySQL inserts three tables with different values. The association condition is the primary foreign key. How about the syntax of the insertion statement?
猜你喜欢

Programmer's Guide to health quenching 5: introduction to sports Basics
![[matlab] download originality documents based on oil monkey script and MATLAB](/img/c2/1788b758778ba73dd02fb0d006869e.png)
[matlab] download originality documents based on oil monkey script and MATLAB

ROS_ Rqt toolbox

黑盒(功能)测试基本方法

Leetcode-6131: the shortest dice sequence impossible to get

Test cases and defect report templates

leetcode-6130:设计数字容器系统

Canvas 填充渐变

Google guava is just a brother. What is the real king of caching? (glory Collection Edition)

DDD go practice
随机推荐
Illustration leetcode - 3. longest substring without repeated characters (difficulty: medium)
有哪些优化mysql索引的方式请举例(sqlserver索引优化)
zigbee物联网开发平台(工业物联网)
【单细胞高级绘图】07.KEGG富集结果展示
Online XML to JSON tool
yuv422转rgb(422sp转420p)
Leetcode skimming -- guess the size of numbers II 375 medium
Interface testing tool restlet client
Huatai Securities account opening process, is it safe to open an account on your mobile phone
Using the OAP aspect causes the controller to be called repeatedly
Today's sleep quality record 75 points
[matlab] download originality documents based on oil monkey script and MATLAB
[MCU] 51 MCU burning those things
leetcode-114:二叉树展开为链表
Leetcode-6129: number of all 0 subarrays
Leetcode-6125: equal row and column pairs
Matlab---eeglab check EEG signal
leetcode-6127:优质数对的数目
牛客-TOP101-BM37
leetcode-155:最小栈