当前位置:网站首页>Appium自动化测试基础 — APPium基础操作API(一)
Appium自动化测试基础 — APPium基础操作API(一)
2022-07-05 15:04:00 【测试-八戒】
1、前置代码
一个脚本中必须要编写的内容:
# server 启动参数
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'
# 声明driver对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
2、安装和卸载APP
(1)把电脑中的APK安装包,安装到手机上
安装方法:
driver.install_app(app_path)
参数:
app_path:脚本机器中APK⽂件路径
(2)卸载手机上已安装的APP
卸载方法:
driver.remove_app(app_id)
参数:
app_id:需要卸载的app包名
(3)演示练习
# 1.导入appium
import time
from appium import webdriver
# 2.创建Desired capabilities对象,添加启动参数
desired_caps = {
"platformName": "Android", # 系统名称
"platformVersion": "7.1.2", # 系统版本
"deviceName": "127.0.0.1:21503", # 设备名称
"appPackage": "com.microvirt.launcher2", # APP包名
"appActivity": "com.microvirt.launcher.Launcher" # APP启动名
}
# 3.启动APP
# 声明手机驱动对象(实例化webdriver)
# 第一个参数为appium服务的地址,需要启动appium服务。
# 第二个参数为Desired capabilities对象
# 我们就先传入这两个参数就可以了。
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 4.操作APP
# 脚本机器中APK⽂件路径,注意前边要加一个r,不然解析地址时可能会报错。
app_path = r'C:\Users\L\Desktop\com.taobao.taobao_V9.15.0.apk'
# 安装apk
driver.install_app(app_path)
time.sleep(5)
# 要知道即将卸载的app的包名
app_id = "com.taobao.taobao"
# 卸载app
driver.remove_app(app_id)
# 5.关闭APP
time.sleep(3)
driver.quit()
说明:
一般这两个命令很少使用,即使用命令安装apk软件,一般我们也推荐使用adb命令。就不用把安装app的代码写入脚本中,即使写入脚本,最终执行也是adb命令。如果公司的测试机充裕,我们就把app的安装包放入手机,直接手动安装了。
一般用到这两个命令是在一个脚本要去测试多个app的时候,会用到这两个命令,在测试时把这几个app先安装上,测试完成之后在卸载app。但是这种情况也基本上不多,一般情况app都单独测试。
3、判断APP是否已安装
使用的API:
driver.is_app_installed(bundle_id)
参数:
bundle_id: 传⼊app包名,返回结果为True(已安装) / False(未安装)
示例:
# 1.导入appium
import time
from appium import webdriver
# 2.创建Desired capabilities对象,添加启动参数
desired_caps = {
"platformName": "Android", # 系统名称
"platformVersion": "7.1.2", # 系统版本
"deviceName": "127.0.0.1:21503", # 设备名称
"appPackage": "com.microvirt.launcher2", # APP包名
"appActivity": "com.microvirt.launcher.Launcher" # APP启动名
}
# 3.启动APP
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 4.操作APP
# 脚本机器中APK⽂件路径
app_path = r'C:\Users\L\Desktop\com.taobao.taobao_V9.15.0.apk'
# 安装apk
driver.install_app(app_path)
time.sleep(5)
# 要知道即将卸载的app的包名
bundle_id = "com.taobao.taobao"
result = driver.is_app_installed(bundle_id)
# 结果是result=true
print(result)
# 5.关闭APP
time.sleep(3)
driver.quit()
提示:一般我们用眼看app是否安装就可以了,脚本中明确需要的时候再写。
4、关闭app软件和关闭驱动对象
关闭app软件和关闭驱动对象的区别:
driver.close_app()
闭当前操作的app,不会关闭驱动对象。driver.quit()
关闭驱动对象,同时关闭所有关联的app。
重点:配套学习资料和视频教学
那么在这里我也精心准备了上述大纲的详细资料在下方链接如下
边栏推荐
- 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
- JMeter performance test: serveragent resource monitoring
- sql server学习笔记
- MySQL之CRUD
- Database learning - Database Security
- [recruitment position] infrastructure software developer
- Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
- P1451 求细胞数量/1329:【例8.2】细胞
- Stm32+bh1750 photosensitive sensor obtains light intensity
- CODING DevSecOps 助力金融企业跑出数字加速度
猜你喜欢
百亿按摩仪蓝海,难出巨头
Coding devsecops helps financial enterprises run out of digital acceleration
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
Huawei Hubble incarnation hard technology IPO harvester
Bugku telnet
OSI 七层模型
1330: [example 8.3] minimum steps
30岁汇源,要换新主人了
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
MySQL之CRUD
随机推荐
我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
Anti shake and throttling
"Sequelae" of the withdrawal of community group purchase from the city
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
JS bright blind your eyes date selector
Redis' transaction mechanism
Usage and usage instructions of JDBC connection pool
[recruitment position] infrastructure software developer
MySQL之CRUD
Magic methods and usage in PHP (PHP interview theory questions)
Reasons and solutions for redis cache penetration and cache avalanche
P6183 [USACO10MAR] The Rock Game S
Definition of episodic and batch
百亿按摩仪蓝海,难出巨头
30岁汇源,要换新主人了
Coding devsecops helps financial enterprises run out of digital acceleration
[12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
sql server学习笔记
I spring and autumn blasting-1
DVWA range clearance tutorial