https://github.com/openatx/facebook-wda
前置条件
- 安装
- 安装依赖
- brew install carthage
- brew install node
- brew install libimobiledevice --HEAD
- 克隆wda代码
- git clone https://github.com/appium/WebDriverAgent
- 初始化wda
- cd ./WebDriverAgent
- ./Scripts/bootstrap.sh
- 打开Xcode
- 方法1:在WebDriverAgent文件下打开 WebDriverAgent.xcodeproj 文件
- 方法2:直接打开xcode,选择WebDriverAgent文件
- 配置xcode
- 配置WebDriverAgentLib和WebDriverAgentRunner
- 参考:https://testerhome.com/topics/7220
- 账号:apple id
- 选择WebDriverAgentRunner和设备
- 无报错提示后command + U运行
- 手机会安装wda无图标APP,首次安装,需要进行信任
- 如果更改了build号,需要先删除手机旧wda
- iproxy 8100 8100 # 端口转发
- 配置WebDriverAgentLib和WebDriverAgentRunner
- 检查wda环境
- 浏览器输入localhost:8100/status,出现josn格式返回 (需先接口转发)
- 获取控件元素
- 使用atx,同Android的uiautomator2
- python3 -m weditor
- 安装依赖
- 每次使用
- 开启Xcode
- 选择手机,(product-destination)
- command + U(product-test)运行成功(bulid success 然后自动手机装wda程序)
- 如果提示报错,需要手机信任(设置-通用-描述文件与设备管理)
- 控制台运行 iproxy 8100 8100 (端口转化,港版的手机不需要)
- 控制台运行 python3 -m weditor (开启weditor,使用http://localhost:8100连接)
- 开启Xcode
配置
- import wda
- wda.DEBUG = False # 默认为false
- wda.HTTP_TIMEOUT = 60.0 # 默认为60s
连接手机
- 创建一个连接
- 使用Client
- 先引用 import wda
- c = wda.client('http://localhost:8100’)
- c = wda.client()
- 不设置参数,则默认从 $DEVICE_URL 获取,
- 如果$DEVICE_URL为空,则默认为http://localhost:8100
- 如果连接出错,会报wda.WDAError错误
- 使用USBClient
- USBClient继承自Client
- USBClient通过unix:/var/run/usbmuxd连接到wda-server服务
- import wda
- 当只有一个设备连接时,可以不用填参数
- c = wda.USBClient()
- 支持指定设备的udid和wda的端口号
- c = wda.USBClient(“539c5fffb18f2be0bf7f771d68f7c327fb68d2d9”, port=8100)
- 支持通过device_url访问
- c = wda.Client(“usbmux://{udid}:8100”.format(udid=“539c5fffb18f2be0bf7f771d68f7c327fb68d2d9”))
- 使用Client
Client
- 显示状态
- c.status()
- 等待wda准备好
- c.wait_ready(timeout=300) # 等待300s,不设置默认120s
- c.wait_ready(timeout=300, noprint=True) # 安静的等待,无进度输出
- 按home键
- c.home()
- 健康检查
- c.healthcheck() (health-健康)
- 获取页面源 (source-资源)
- c.source() # 格式为xml
- c.source(accessible=True) # 默认为false ,格式为json
- 锁定屏幕
- c.locked() #检查屏幕锁定状态 返回 true或false
- c.lock() #锁定屏幕
- c.unl