基于facebook-wda的iOS自动化操做实践记录

[本文出自天外归云的博客园]python

原理

对于iOS自动化操做,主要靠WebDriverAgent来完成。在Mac电脑上链接真机iPhone,运行WebDriverAgentRunner会在Mac端启动WDA服务器,并在手机iPhone端安装一个WebDriverAgentRunner应用。咱们经过编写脚原本与WDA服务器通讯,告诉WDA服务器咱们想要如何操做iPhone手机,WDA服务器与安装在手机iPhone端的WebDriverAgentRunner应用通讯并经过该app发送模拟指令来实现操做iPhone手机git

安装过程

1. 安装WebDriverAgent:https://github.com/facebook/WebDriverAgentgithub

2. 及其依赖的库Carthage:https://github.com/Carthage/Carthagenpm

3. 须要npm的支持xcode

启动与中止WDA服务器

方式1:命令行启动模拟器 xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS Simulator,name=iPhone 6' test服务器

方式2:在真机上运行参考这篇文章进行配置:ATX 文档 - iOS 真机如何安装 WebDriverAgentsession

中止运行WDA:Xcode-Product-Stopapp

安装并了解facebook-wda的用法

1. 安装wda的python库:pip install facebook-wda函数

2. 了解facebook-wdaui

遇到的问题与解决方法

1. 从app安装包的plist文件中查看iOS应用的bundleId

2. 经过facebook-wda点击home键报错解决办法: “这个是wda的问题,判断桌面是否出现致使了超时,英文系统是Docker,中文系统是程序坞”,解决方法是更改WebDriverAgent文件夹下WebDriverAgentLib文件夹下的FBSpringboardApplication.m文件中fb_isApplicationBoardVisible函数的返回为return self.otherElements[@"Dock"].isEnabled || self.otherElements[@"程序坞"].isEnabled;

编写脚本

能够经过编写运行python脚本,经过调用wda封装的方法,与WebDriverAgentRunner运行的服务器交互。实现一些自定义的行为,达到操控iPhone的目的。例如:

import wda

c = wda.Client('http://WDAServer的ip:8100')
print(c.status())
c.healthcheck()
c.home()
s = c.session('app的bundleId')
s(text="跳过").click_exists(timeout=5.0)
s(text="广场").click_exists(timeout=5.0)
s.close()

以上表明的基本关键操做以下:

1. 链接已经运行起来的WebDriverAgentRunner服务器,在xcode的终端能够看到WDAServer的ip

2. 经过app的bundleId来启动app

3. 判断是否有指定文字的按钮并点击,设置超时时间为5s

相关文章
相关标签/搜索