Appium

本片文章仅仅是自己学习Appium时,个人理解,如有错误还请大家指出,共同学习😁

介绍

Appium是移动端自动化测试框架,跨平台(支持iOS和Android、Windows、Mac)且支持多语言(Java、Python、C、JS等)。
Appium可用于测试原生应用、移动网页应用和混合应用。

  • 原生应用:是指用Android或者iOS编写的应用,使用各平台自带的组件开发的应用
  • 移动网页应用:网页应用,可以使用浏览器打开的应用
  • 混合应用:使用原生应用内嵌了网页交互内容的应用,比如使用了webview的应用

1、底层引擎

Android平台

  • Espresso Driver
  • UiAutomator2 Driver
  • UiAutomator Driver
    已废弃
  • Selendroid Driver
  • 已废弃

iOS平台

  • XCUITest Driver
  • UiAutomation Driver
    ios9.3之前使用的是UiAutomation

Windows平台

  • Windows Driver

Mac平台

  • Mac Driver

2、设计理念

请添加图片描述
请添加图片描述

Appium是C/S模式,是HTTP协议通信模式。通信前需要建立连接,如创建session会话。然后执行通信。

工作原理

  1. 驱动即Appium Client发送请求给Appium Server
  2. Appium Server再将消息发送给功能引擎,比如UiAutomator2 Driver
  3. 功能引擎再将消息发送给移动端的引擎服务器,比如UiAutomator2 Driver发送消息给Android设备上的UiAutomator2 Server
  4. 终端的引擎服务器再将消息转换成操作命名会给设备上的守护进程执行
  5. 最后结果将一层一层向上返回

The Mobile JSON Wire Protocol

Selenium支持的是The JSON Wire Protocol,Appium在此基础之上新增了支持移动设备的协议

使用shell模拟发送各种请求操作
  1. 保证Appium已启动
  2. 发送创建session请求
    此时Appium会创建session并且启动app
curl -l -H "Content-type: application/json" -X POST -d '{"desiredCapabilities":{"platformName":"Android","deviceName":"9a9f3d5d","appPackage":"com.tencent.wework","appActivity":".launch.LaunchSplashActivity","noReset":true,"newCommandTimeout":120,"udid":"9a9f3d5d","dontStopAppOnReset":false}}' 'http://127.0.0.1:4723/wd/hub/session'
  1. 获取到sessionId
    发送获取session信息请求
curl 'http://127.0.0.1:4723/wd/hub/sessions'
  • 获取sessionId
sessionId=$(curl 'http://127.0.0.1:4723/wd/hub/sessions' \ | awk -F\" '{print $6}')

echo ${sessionId}
  1. 获取到定位元素id
curl -X POST http://127.0.0.1:4723/wd/hub/session/${sessionId}/elements --data-binary '{"using":"xpath", "value":"//*[@text=\"通讯录\"]"}' -H "Content-Type: application/json;charset=UTF-8"
  • 获取元素id
elementId=$(curl -X POST http://127.0.0.1:4723/wd/hub/session/${sessionId}/elements --data-binary '{"using":"xpath", "value":"//*[@text=\"通讯录\"]"}' -H "Content-Type: application/json;charset=UTF-8" \ | awk -F\" '{print $6}')

echo ${elementId}
  1. sessionId和elementId拿到之后,我们就可以进行操作了,如获取属性、点击、赋值等操作
  • 获取文本属性
curl http://127.0.0.1:4723/wd/hub/session/${sessionId}/element/${elementId}/attribute/text
  • 点击元素
curl -X POST http://127.0.0.1:4723/wd/hub/session/${sessionId}/element/${elementId}/click
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值