当前位置:网站首页>Appium基础 — 使用Appium的第一个Demo
Appium基础 — 使用Appium的第一个Demo
2022-07-05 05:50:00 【测试-八戒】
我们使用Python语言作为测试脚本的编写语言。
执行脚本前提:
- Android模拟器或者手机是开机状态。
- 使用确保电脑和Android设备进行了链接。
也就是使用ADB命令adb connect链接设备,
或者通过adb devices命令能够查看到设备。 - 开启Appium服务。
在Python的开发IDE中(PyCharm)中编写脚本如下:
"""
1.学习目标
掌握appium启动手机方法
2.操作步骤
1-说明:明确驱动对象(操作对象)
web自动化步骤:
1.指定启动浏览器
2.输入网址
3.继续其他操作...
APP自动化步骤:
要先传递如下信息:
系统名称: Android IOS
系统版本: 版本号
设备名称: 通过adb devices命令获取
APP包名: 打开哪个APP
APP启动名:进入APP哪个页面
2-导入appium中webdriver
3-添加启动参数
设备信息
系统名称: Android IOS
系统版本: 版本号
设备名称: adb devices
APP信息
APP包名: 打开哪个APP
APP启动名:进入APP哪个页面
4-启动app
webdriver.Remote()
5-操作app
6-关闭app
3.需求
启动Android模拟器中的设置APP
"""
# 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.android.settings", # APP包名
"appActivity": ".Settings" # APP启动名
}
"""
说明:
deviceName :
cmd进入命令行终端
输入adb connect 127.0.0.1:21503 链接逍遥模拟器
输入adb devices 获取设备名称
appPackage和appActivity获取:
首先在虚拟机中打开设置
输入命令adb shell dumpsys window windows | findstr mFocusedApp
在u0之后的就是包名和启动名com.android.settings/.Settings
"""
"""
提示:
platformName字段中Android和android大小写都可以。
deviceName 字段,在测试Android手机时,随意写都可以,比如123
因为deviceName字段是针对IOS系统的,
对于Android系统,该字段必须要有,但是内容可以随意写,且不能为空。
platformVersion 字段写两位也可以,能够运行。
"""
# 3.启动APP
# 声明手机驱动对象(实例化webdriver)
# 第一个参数为appium服务的地址,需要启动appium服务。
# 第二个参数为Desired capabilities对象
# 我们就先传入这两个参数就可以了。
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# http://127.0.0.1:4723/wd/hub 中/wd/hub这个是固定的,必须有,要求的。
# 上面的一步就已经把app启动起来了。
# 4.操作APP
# 先不对app做任何操作。
# 5.关闭APP
time.sleep(5)
driver.quit()
提示:
运行appium代码注意事项:
1.保证设备(手机)和电脑连接成功的
就是使用adb connect命令链接了设备
或者adb devices可以查看到设备名称
2.运行appium server(服务是启动的)
3.执行测试代码即可。
注意:如果是第一次运行Appium脚本,会在你的手机中安装一个叫Appium Settings的App。

最后我们来看一下Appium服务的日志大概都说了些什么内容,如下:
[Appium] Welcome to Appium v1.13.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
# 一个session
[HTTP] --> POST /wd/hub/session
# 传入Desired capabilities字典类型对象
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:platformVersion":"7.1.2","appium:deviceName":"127.0.0.1:21503","appium:appPackage":"com.android.settings","appium:appActivity":".Settings"}]},"desiredCapabilities":{"platformName":"Android","platformVersion":"7.1.2","deviceName":"127.0.0.1:21503","appPackage":"com.android.settings","appActivity":".Settings"}}
# 启动AppiumDriver,创建回话
[W3C] Calling AppiumDriver.createSession() with args:
...省略部分信息...
# 然后启动一些ADB命令
[ADB] Found 2 'build-tools' folders under 'F:\DevInstall\envs\android-sdk-windows' (newest first):
[ADB] F:/DevInstall/envs/android-sdk-windows/build-tools/29.0.3
...省略部分信息...
[BaseDriver] Event 'newSessionStarted' logged at 1605778307025 (17:31:47 GMT+0800 (中国标准时间))
# 6d2f52a7-f71e-4842-98e9-22aff59a4b38 为sessionID
[W3C (6d2f52a7)] Cached the protocol value 'W3C' for the new session 6d2f52a7-f71e-4842-98e9-22aff59a4b38
...省略部分信息...
[BaseDriver] Event 'quitSessionFinished' logged at 1605778313510 (17:31:53 GMT+0800 (中国标准时间))
[W3C (6d2f52a7)] Received response: null
[W3C (6d2f52a7)] But deleting session, so not returning
[W3C (6d2f52a7)] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/6d2f52a7-f71e-4842-98e9-22aff59a4b38 200 1469 ms - 14
[HTTP] 提示:
- 安卓应用的后缀是
.apk,是AndroidPackage的缩写。 - IOS安装包
.ipa,安装ios测试版本,需要Ios开发将iPhone手机的UUID编号加入到开发者项目。
重点:配套学习资料和视频教学
那么在这里我也精心准备了上述大纲的详细资料在下方链接如下


边栏推荐
- 7. Processing the input of multidimensional features
- 2022年貴州省職業院校技能大賽中職組網絡安全賽項規程
- Spark中groupByKey() 和 reduceByKey() 和combineByKey()
- 884. Uncommon words in two sentences
- Annotation and reflection
- sync. Interpretation of mutex source code
- Cluster script of data warehouse project
- kubeadm系列-00-overview
- js快速将json数据转换为url参数
- CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
猜你喜欢
![[jailhouse article] performance measurements for hypervisors on embedded ARM processors](/img/c0/4843f887f77b80e3b2329e12d28987.png)
[jailhouse article] performance measurements for hypervisors on embedded ARM processors

用STM32点个灯

【云原生】微服务之Feign自定义配置的记录

Implement an iterative stack

Personal developed penetration testing tool Satania v1.2 update

Some common problems in the assessment of network engineers: WLAN, BGP, switch

Typical use cases for knapsacks, queues, and stacks

Sword finger offer 04 Search in two-dimensional array

2017 USP Try-outs C. Coprimes

【Jailhouse 文章】Jailhouse Hypervisor
随机推荐
[jailhouse article] performance measurements for hypervisors on embedded ARM processors
1.15 - 输入输出系统
Implement an iterative stack
How to adjust bugs in general projects ----- take you through the whole process by hand
Educational Codeforces Round 107 (Rated for Div. 2) E. Colorings and Dominoes
中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
LeetCode 1200.最小绝对差
leetcode-3:无重复字符的最长子串
剑指 Offer 05. 替换空格
Bit mask of bit operation
对for(var i = 0;i < 5;i++) {setTimeout(() => console.log(i),1000)}的深入分析
SSH password free login settings and use scripts to SSH login and execute instructions
Binary search template
Sword finger offer 58 - ii Rotate string left
Some common problems in the assessment of network engineers: WLAN, BGP, switch
leetcode-1200:最小绝对差
每日一题-无重复字符的最长子串
Scope of inline symbol
卷积神经网络简介
Reader writer model