一、 Appium自动化四原则:
1 没有必要为了自动化而重新编译你的应用或者以任何方式修改它
Android/iOS系统自带框架
2 不应该被限制在特定的语言和框架上来编写运行用例
WebDriver API一、
客户端-服务器协议(称为JSON Wire Protocol) http-command
3 移动端自动化框架在自动化接口方面不应该重造轮子,find_element\click send_keys
WebDriver --- Web浏览自动化的标准, get_attribute text
附加可用于移动端自动化的API方法
python --appium server -移动端
4 移动端自动化框架应该开源,不但在名义上而且在精神上和实质上都要实至名归
Appium开源
二、 Appium工具配置介绍
1. 高级设置模块:Advance
1) Logfile Path : 日志路径
2) Log Level : 日志等级,默认DEBUG
3) Local Timezone / Log Timestamps : 日志时间(都勾选,打印日志时就会有时间)
4) Allow Session Override: 允许会话重写,当在执行某个设备会话中间出错,Appium server 等待60s才会结束,但我们想直接继续下一个会话开始,那么就可以勾选这个
2. Appium Server日志界面
1) ”搜索“图标:(可以使用此来定位)
点击图标
- Automatic Server ---> Desired Capabilities 下方填入设备以及设备APP相关信息并保存
- 模拟器/真机要开启,且已安装APP
- Start Session之后,就会出现启动APP
# 新界面元素:
1) 选元素
2) 通过坐标滑动(Swipe by coordernates)
3) 坐标点击(Tap by coordernates)
4) 返回上一个 <-
5) 刷新当前界面
6) 录制: Start Recording
录制的过程中都是坐标说明
7) Source : 源码
8) Select Element 模块:
-- Xpath定位表达式
-- 元素属性:可以帮助我们定位元素
-- 顶部栏:
1) Tap点击操作:点击之后,点击Tap,界面就会刷新
2) ”下载“图标:日志配置
可以下载下来本地,查看日志
3) ”暂停“图标: 服务终止,当点击之后,Appium server会话就会终止
三、 APP内部元素怎么定位呢?
1. UiAutomator工具打开在保证设备App打开情况下
1) Android\tools目录下的UiAutomator.bat双击
2) 新出现的界面,点击左上角第二个图标 ,此时就会出现设备APP当前的界面
3) 左侧界面显示效果,右侧显示元素布局
元素属性:
1) resource-id: 风格一样的元素,查看resource-id是否一样,不一样的化,则可以用id来定位
2) class: Appium中class相当于Web端的标签名:tag, 可以用来定位
3) conten-desc: 内容描述
4) checkable: 是否可选(单选框、复选框)----能力
5) checked : 当前的状态,是否是已选中的状态----状态
6) clickable: 是否可点击
7) enable : 是否可见,是否可用(可见即可用)
Appium元素定位方式?
1) id : resource-id --- -常用
2) className: classname --- 常用
3) Xpath
4) Accessibility id : 根据这个值content-desc来定位
5) -android UiAutomator 定位(通过AndroidAutomator来定位)----常用
6) 坐标定位(一般不用)
AndroidUiAutomator介绍 :
1) 学习网站
UiAutomator : https://developer.android.google.cn/training/testing/ui-automator#java
UiSelector定位方式 : https://developer.android.google.cn/reference/androidx/test/uiautomator/UiSelector.html
appium- 元素定位表达式(类)、找元素、元素对象、设备对象
在APP自动化中,优先使用: AndroidAutomator 来定位
组合定位(class & text一起定位):
2) UiAumator定位表达式
# new UiSelector().函数名1(参数) 返回的还是一个self,所以可以继续:new UiSelector().函数名1(参数).函数名2()
loc = 'new UiSelector().className("android.widget.TextView").text("就业信息")'
driver.find_element_by_android_uiautomator(loc)
2. Appium自带的定位工具
参考内容: 2. Appium Server日志界面
1) ”搜索“图标:(可以使用此来定位)
3. 第三种定位工具
APP元素定位 - 第三种定位工具: http://www.lemfix.com/topics/346 (本班 秦时明月 著作哦! )
工具说明地址:https://github.com/thanksdanny/uiautomator2/blob/master/README.md 混合应用 - 不需要开户webview debug来操作html页面方式:
https://www.cnblogs.com/yyoba/p/11149614.html
# 环境准备
1) pip install pillow
2) pip install --pre uiautomator2
# Since uiautomator2 is still under development, you have to add --pre to install the development version
pip install --pre uiautomator2
# Or you can install directly from github source git clone https://github.com/openatx/uiautomator2
pip install -e uiautomator2
安装完成后,需要再安装: python -m uiautomator2 init
3) Install weditor(UI Inspector)
pip install --pre -U weditor
Windows系统可以使用命令在桌面创建一个快捷方式 python -m weditor --shortcut
命令行启动 python -m weditor 会自动打开浏览器,输入设备的ip或者序列号,点击Connect即可。
weditor --help 确认是否安装成功了。
4) 安装Xposed
下载地址: https://repo.xposed.info/module/de.robv.android.xposed.installer