美文网首页
uiautomator2+python自动化测试2-抓元素利器w

uiautomator2+python自动化测试2-抓元素利器w

作者: HAO延WEI | 来源:发表于2019-07-20 12:06 被阅读0次

1.weditor环境准备:

使用pip安装weditor,github地址https://github.com/openatx/weditor

  • python环境:2.7
  • 安装:pip install weditor
  • 安装:pip install uiautomator2

2.运行:

  • python -m weditor
  • python -m uiautomator2 init

看到窗口出现如下信息,就是启动成功了(窗口别关掉了)

C:\Users\dell>python -m weditor
listening on http://192.168.1.125:17310
[I 190717 23:50:55 web:2246] 304 GET / (::1) 7.98ms
[I 190717 23:50:55 web:2246] 304 GET /static/libs/css/buttons.css (::1) 196.47ms
[I 190717 23:50:55 web:2246] 304 GET /static/loading.svg (::1) 5.99ms
[I 190717 23:50:55 web:2246] 304 GET /static/ace/ace.js (::1) 12.97ms
[I 190717 23:50:55 web:2246] 304 GET /static/running.svg (::1) 13.96ms
[I 190717 23:50:55 web:2246] 304 GET /static/ace/mode-python.js (::1) 19.96ms
[I 190717 23:50:55 web:2246] 304 GET /static/libs/fontawesome/css/font-awesome.min.css (::1) 1.99ms
[I 190717 23:50:59 web:2246] 304 GET /api/v1/version (::1) 0.00ms

3.weditor连接手机

先使用adb连上手机,输入adb devices查看手机设备号:

C:\Users\dell>adb devices
List of devices attached
adb server version (31) doesn't match this client (40); killing...
* daemon started successfully
emulator-5554   device

在页面上输入手机设备号,点Connet按钮,看到出现一个小草的图标,就是连接成功了


image.png
4.页面元素抓取

定位元素
定位元素的方法支持uiautomator的定位方法,也可以支持xpath和坐标定位

  • 1.可以查看元素的resourceId属性
  • 2.自动生成xpath定位方法
  • 3.支持坐标点击,根据屏幕的比例
  • 4.自动生成uiautomator定位方法参考代码
  • 5.可以勾选强制使用xpath
    image.png
    操作步骤:点勾选高铁动车后,点查询按钮
    Ctr+Enter运行代码,会发现手机上已经点击成功
5.在线Coding调试

可以在页面的右边调试运行代码,这点比appium强很多,可以编写代码边调试,还是非常方便的


6.支持wifi连接

首先保证电脑和手机wifi在一个局域网,电脑上能ping的通手机的ip,输入手机的ip也可以抓到手机上的页面元素。

相关文章

网友评论

      本文标题:uiautomator2+python自动化测试2-抓元素利器w

      本文链接:https://www.haomeiwen.com/subject/qjwylctx.html