玩玩 WebDriverAgent

/ 0评 / 2

一、简介

WebDriverAgent是 Facebook 推出了一款新的iOS移动测试框架,模拟器和真机都支持,可以去Github看看介绍

WebDriverAgent is a WebDriver server implementation for iOS that can be used to remote control iOS devices. It allows you to launch & kill applications, tap & scroll views or confirm view presence on a screen. This makes it a perfect tool for application end-to-end testing or general purpose device automation. It works by linking XCTest.framework and calling Apple's API to execute commands directly on a device. WebDriverAgent is developed and used at Facebook for end-to-end testing and is successfully adopted by Appium.

总体就是说 WebDriverAgent 在 iOS 端实现了一个 WebDriver server,借助这个 server 我们可以远程控制 iOS 设备。你可以启动、杀死应用,点击、滚动视图,或者确定页面展示是否正确。它是iOS上一个完美的e2e的自动化解决方案,链接XCTest.framework调用苹果的API直接在设备上执行命令。吧啦吧啦一大堆。。。

二、准备工作

需要先安装三方管理工具carthage,之前写过,这里不做太多介绍

brew install carthage

有些iPhone通过手机的IP和端口不能访问,比如我的,此时需要将手机的端口转发到Mac上

brew install libimobiledevice --HEAD

克隆 WebDriverAgent 仓库

git clone https://github.com/facebook/WebDriverAgent

cd进WebDriverAgent的目录,在这里执行下面的脚本,不要再进入Scripts目录了

./Scripts/bootstrap.sh  

三、配置运行

安装到真机上需要开发者证书,我这里直接用的免费证书,按照下面的图改掉配置就OK了。
Team那一栏,选择你的开发者证书帐号:

接着在TARGETS里面选中WebDriverAgentRunner,先改掉包名

用上面同样的方法设置好证书

下面就选好运行环境,直接 Product->Test 就可以运行了

不报错的话,手机上会出现一个无图标的WebDriverAgent应用,启动之后,马上又返回到桌面,这是很正常滴。
这时候就需要转发一下端口

iproxy 8100 8100

然后打开浏览器直接访问

http://localhost:8100/status #查看状态
http://localhost:8100/inspector #inspector是用来查看UI的图层

四、自动化脚本

通常来说为了持续集成,能够全部自动化比较好一些,下面的脚本保存到一个shell文件中运行即可,就不需要打开Xcode了

# 解锁keychain,以便可以正常的签名应用,
PASSWORD="replace-with-your-password"
security unlock-keychain -p $PASSWORD ~/Library/Keychains/login.keychain

# 获取设备的UDID
UDID=$(idevice_id -l | head -n1)

# 运行测试
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$UDID" test

评论已关闭。