当前位置:网站首页>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编号加入到开发者项目。
重点:配套学习资料和视频教学
那么在这里我也精心准备了上述大纲的详细资料在下方链接如下


边栏推荐
- Daily question 2013 Detect square
- Sword finger offer 05 Replace spaces
- Smart construction site "hydropower energy consumption online monitoring system"
- API related to TCP connection
- 一些工具的记录2022
- One question per day 1447 Simplest fraction
- Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
- 用STM32点个灯
- AtCoder Grand Contest 013 E - Placing Squares
- Talking about JVM (frequent interview)
猜你喜欢

Fried chicken nuggets and fifa22

Scope of inline symbol

CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five

leetcode-6108:解密消息

2017 USP Try-outs C. Coprimes

API related to TCP connection

剑指 Offer 05. 替换空格

shared_ Repeated release heap object of PTR hidden danger

Palindrome (csp-s-2021-palin) solution

leetcode-6110:网格图中递增路径的数目
随机推荐
Hang wait lock vs spin lock (where both are used)
R语言【数据集的导入导出】
Using HashMap to realize simple cache
Smart construction site "hydropower energy consumption online monitoring system"
LaMDA 不可能觉醒吗?
Detailed explanation of expression (csp-j 2021 expr) topic
Over fitting and regularization
Daily question 1342 Number of operations to change the number to 0
Sword finger offer 04 Search in two-dimensional array
A problem and solution of recording QT memory leakage
Brief introduction to tcp/ip protocol stack
Simply sort out the types of sockets
Sword finger offer 35 Replication of complex linked list
剑指 Offer 06.从头到尾打印链表
Solution to the palindrome string (Luogu p5041 haoi2009)
游戏商城毕业设计
一些工具的记录2022
Reader writer model
Codeforces Round #715 (Div. 2) D. Binary Literature
Personal developed penetration testing tool Satania v1.2 update