当前位置:网站首页>Appium automation test foundation - appium basic operation API (I)
Appium automation test foundation - appium basic operation API (I)
2022-07-05 15:29:00 【Test - Eight Precepts】
1、 Pre code
What must be written in a script :
# server Launch parameters
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '192.168.56.101:5555'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
# Statement driver object
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)2、 load and unload APP
(1) Put the... In the computer APK Installation package , Install on your phone
Installation method :
driver.install_app(app_path)
Parameters :
app_path: In the script machine APK⽂ Piece path (2) Uninstall the installed on your phone APP
Uninstall method :
driver.remove_app(app_id)
Parameters :
app_id: Need to unload app Package name (3) Demonstration exercise
# 1. Import appium
import time
from appium import webdriver
# 2. establish Desired capabilities object , Add startup parameters
desired_caps = {
"platformName": "Android", # System name
"platformVersion": "7.1.2", # System version
"deviceName": "127.0.0.1:21503", # Equipment name
"appPackage": "com.microvirt.launcher2", # APP Package name
"appActivity": "com.microvirt.launcher.Launcher" # APP Start name
}
# 3. start-up APP
# Declare the mobile phone driver object ( Instantiation webdriver)
# The first parameter is zero appium Address of service , Need to start the appium service .
# The second parameter is Desired capabilities object
# Let's just pass in these two parameters first .
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 4. operation APP
# In the script machine APK⽂ Piece path , Be careful to add a... In front r, Otherwise, an error may be reported when resolving the address .
app_path = r'C:\Users\L\Desktop\com.taobao.taobao_V9.15.0.apk'
# install apk
driver.install_app(app_path)
time.sleep(5)
# You know what you're about to uninstall app The package name
app_id = "com.taobao.taobao"
# uninstall app
driver.remove_app(app_id)
# 5. close APP
time.sleep(3)
driver.quit() explain :
In general, these two commands are rarely used , That is, use the command to install apk Software , Generally, we also recommend adb command . You don't have to install app Write your code into the script , Even if you write a script , The final execution is also adb command . If the company has enough testing machines , We will take app Put the installation package into the mobile phone , Installed directly and manually .
These two commands are usually used in a script to test multiple app When , These two commands will be used , Put these in the test app First install , After the test is completed, uninstall app. But this situation is basically not much , General situation app All tested separately .
3、 Judge APP Installed or not
The use of API:
driver.is_app_installed(bundle_id)
Parameters :
bundle_id: Pass on ⼊app Package name , The return result is True( already installed ) / False( Not installed )Example :
# 1. Import appium
import time
from appium import webdriver
# 2. establish Desired capabilities object , Add startup parameters
desired_caps = {
"platformName": "Android", # System name
"platformVersion": "7.1.2", # System version
"deviceName": "127.0.0.1:21503", # Equipment name
"appPackage": "com.microvirt.launcher2", # APP Package name
"appActivity": "com.microvirt.launcher.Launcher" # APP Start name
}
# 3. start-up APP
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 4. operation APP
# In the script machine APK⽂ Piece path
app_path = r'C:\Users\L\Desktop\com.taobao.taobao_V9.15.0.apk'
# install apk
driver.install_app(app_path)
time.sleep(5)
# You know what you're about to uninstall app The package name
bundle_id = "com.taobao.taobao"
result = driver.is_app_installed(bundle_id)
# The result is result=true
print(result)
# 5. close APP
time.sleep(3)
driver.quit()Tips : Usually we see with our eyes app Whether to install it or not , When the script clearly needs to be written .
4、 close app Software and close driver objects
close app The difference between software and closing driver objects :
driver.close_app()
Close the current operation app, The drive object is not closed .driver.quit()
Turn off the drive object , Close all associated files at the same time app.
a key : Supporting learning materials and video teaching
So here I have carefully prepared the detailed information of the above outline in The link below is as follows


边栏推荐
- 复现Thinkphp 2.x 任意代码执行漏洞
- 漫画:程序员不是修电脑的!
- JS bright blind your eyes date selector
- R 熵权法计算权重及综合得分
- Optional parameters in the for loop
- Ten billion massage machine blue ocean, difficult to be a giant
- Value series solution report
- How can the boss choose programmers to help me with development?
- [JVM] operation instruction
- mapper. Comments in XML files
猜你喜欢

Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology

Mysql---- function

Appium自动化测试基础 — APPium基础操作API(一)

Bugku telnet

Ctfshow web entry information collection

No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle

Bugku's steganography

社区团购撤城“后遗症”

Redis' transaction mechanism

Ten billion massage machine blue ocean, difficult to be a giant
随机推荐
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
Common interview questions about swoole
qt creater断点调试程序详解
Hongmeng system -- Analysis from the perspective of business
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
Ten billion massage machine blue ocean, difficult to be a giant
Appium自动化测试基础 — APPium基础操作API(二)
Appium自动化测试基础 — APPium基础操作API(一)
First PR notes
Huiyuan, 30, is going to have a new owner
Redis' transaction mechanism
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
漫画:程序员不是修电脑的!
Severlet learning foundation
P1451 求细胞数量/1329:【例8.2】细胞
Good article inventory
OSI 七层模型
Leetcode: Shortest Word Distance II
sql server char nchar varchar和nvarchar的区别