Xcode9 IOS 真机如何安装 WebDriverAgent自动化测试
WDA在Github的首页上有一个很简单的安装说明 https://github.com/facebook/WebDriverAgent,参考这个,我再增加一些配图,以及自己使用过程中的一些体会。
开始
尽量升级Xcode到最新版,保持iPhone的版本大于9.3
从github上下载代码
git clone https://github.com/facebook/WebDriverAgent
运行初始化脚本
./Scripts/bootstrap.sh
没有安装可以安装
brew install carthage或github下载
执行完成后,直接双击打开WebDriverAgent.xcodeproj这个文件或执行(记得把包名、证书都更换为自己的)
UDID=$(idevice_id -l | head -n1)
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination “id=$UDID” test
执行成功后,通过DEBUG输出给出的IP和端口,加上/status合成一个url地址。例如http://10.0.0.1:8100/status,然后浏览器打开。如果出现一串JSON输出,说明WDA安装成功了。
端口转发
有些国产的iPhone机器通过手机的IP和端口还不能访问,此时需要将手机的端口转发到Mac上。
$ brew install imobiledevice
$ iproxy 8100 8100
使用iproxy –help 可以查到更具体的用法。 这时通过访问http://localhost:8100/status确认WDA是否运行成功。
而inspector的地址是http://localhost:8100/inspector, inspector是用来查看UI的图层,方便写测试脚本用的
自动脚本:
# 解锁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
遇到的错误:
错误1:
dst_ipa: /var/folders/zp/8jcfxwwn0b38w_r237yjt5300000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/WebDriverAgentRunner-Runner.app.IFu6A9/WebDriverAgentRunner-Runner.app_sparse.ipa
MDMDirectoryDiff_block_invoke:1473 calling writeDictToFile with: /var/folders/zp/8jcfxwwn0b38w_r237yjt5300000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/WebDriverAgentRunner-Runner.app.IFu6A9/WebDriverAgentRunner-Runner.app_sparse.ipa/ManifestCache.plist
writeDictToFile:1278 ==== Successfully wrote Manifest cache to /var/folders/zp/8jcfxwwn0b38w_r237yjt5300000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/WebDriverAgentRunner-Runner.app.IFu6A9/WebDriverAgentRunner-Runner.app_sparse.ipa/ManifestCache.plist
2018-01-07 00:00:36.656 xcodebuild[528:4837] Error Domain=IDETestOperationsObserverErrorDomain Code=6 “Early unexpected exit, operation never finished bootstrapping – no restart will be attempted” UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping – no restart will be attempted}
Testing failed:
Early unexpected exit, operation never finished bootstrapping – no restart will be attempted
** TEST FAILED **
错误2:
WebDriverAgentRunner): no suitable image found. Did find:
/var/containers/Bundle/Application/2AD41242-A9B6-41F9-BE8F-A8ECBEB5D9B4/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/WebDriverAgentRunner: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A)
错误3:
Connection peer refused channel request for “dtxproxy:XCTestDriverInterface:XCTestManager_IDEInterface”; channel canceled
解决:
1/sudo xcode-select –switch /Applications/Xcode.app/Contents/Developer/
参考文献:
ATX 文档 – iOS 真机如何安装 WebDriverAgent https://testerhome.com/topics/7220
http://blog.163.com/l1_jun/blog/static/143863882017741031596/
iOS 测试 WebDriverAgent 天坑记 https://testerhome.com/topics/9666
Macaca2.0 升级公告 https://testerhome.com/topics/8687
iOS-remote 安装篇之 WebDriverAgent 安装使用完全指南 https://testerhome.com/topics/10463