项目地址:https://github.com/alibaba/web-editor
简介
在之前进行APP自动化测试的时候使用的是Appium Inspector
WEditor
是基于python的查看APP元素的工具,能够提供辅助编写脚本,定位元素,调试代码等功能。
环境搭建
安装
$ pip3 install weditor
运行
$ weditor
运行后会自动打开http://localhost:17310/#
安卓
获取设备UUID
(base) zhongxin:~ zhongxin$ adb devices
List of devices attached
FURO7TBI4LY56D59 device
172.28.59.131:5555 device
连接设备
选择Android
将设备UUIDFURO7TBI4LY56D59
填入并点击Connect
元素定位
找到需要定位的元素进行点击
比如我们需要定位「门诊记录」
点击后可以看到,右侧给我们展示了它的定位方式
XPathLite //*[@text="门诊记录"]
代码生成
在「门诊记录」上双击可以看到给我们自动生成了代码
# coding: utf-8
#
import uiautomator2 as u2
d = u2.connect()
d.xpath('//*[@text="门诊记录"]').click()
代码调试
可以在右侧代码部分进行调试
IOS
先安装tidevice
MAC:https://blog.csdn.net/dou_being/article/details/120401626
Windows:https://blog.csdn.net/dou_being/article/details/120401944
对于未跑过自动化的iOS设备,我们需要先检查设备上是否安装好了WebDriverAgent这个APP,如未安装,则可以通过以下2种方式安装:
① 将iOS设备与一台Mac连接,然后使用xcode编译源码安装,成功安装WebDriverAgent即可脱离Mac;
② 使用tidevice的安装命令,将开发者证书重签名的 WebDriverAgent.ipa 安装到iOS设备上。
查看手机上的APP
(base) zhongxin:~ zhongxin$ tidevice applist
com.tencent.xin 微信 8.0.16
com.zhongxin.WebDriverAgentRunner490336534.xctrunner WebDriverAgentRunner-Runner 1.0
com.minkanginfo.doctor 微医生(企) 4.4.6
com.lvxian.doctor 微医生 4.4.6
com.happyelements.1OSAnimal 开心消消乐® 1.101.180
com.minkanginfo.guahao 微医(企) 4.4.8
com.ss.iphone.ugc.Aweme 抖音 18.4.0
com.tailor.screenshot.picsew 滚动截屏 1.0.23
me.clarityapp 克拉壁纸 7.2.3
com.fish.stream Stream 1.0.6
com.sugarmo.ScrollClip Picsew 3.7.1
com.lvxian.guahao 微医 4.4.6
启动 WDA
找到APP列表里面的WebDriverAgentRunner-Runner
tidevice wdaproxy -B com.zhongxin.WebDriverAgentRunner490336534.xctrunner --port 8200
访问http://localhost:8200/status
查看是否成功
![测试](/Users/zhongxin/Library/Application Support/typora-user-images/image-20211129174954095.png)
连接手机
点击Dump Hieraerchy
元素定位
操作同安卓
代码生成、代码调试
代码部分需要使用wda
import wda
d = wda.Client('http://localhost:8200')
d.xpath('//*[@label="健康记录仪"]').click()