IOS客户端尝试使用Appium框架进行自动化测试,该框架方便定制符合自身业务的测试用例,提高测试效率。在搭建测试环境时,发现真机调试安装中问题比较多,特整理以供其他遇到同样问题的同学参考。
先列出简单安装流程:
1.
npm install -g appium
2.安装 carthage :brew install carthage
3.npm install -g ios-deploy
4.libimobiledevice:brew install libimobiledevice
5.gem install xcpretty
WebDriverAgent
Runner
的处理:
先使用mac打开终端
1. cd ~
2. 下载WebDriverAgent 项目最新的代码:
git clone
https://github.com/facebook/WebDriverAgent
3. 执行 ./Scripts/bootstrap.sh
4. cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver
5. rm –rf WebDriverAgent 删除自带的WebDriverAgent
6. ln –s ~/WebDriverAgent WebDriverAgent 将编译好的WebDriverAgent放入原来的路径下
7. 打开 WebDriverAgent 项目并按照教程修改, 运行 Product -> Test
(GitHub教程: https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md
)
8. 访问http://10.242.35.210(ip):8100,可以返回一个json。
如果返回失败,可以测试使用下面的方法:
1)转发端口,在终端输入 iproxy 8100 8100 , 窗口不要关闭或者终止运行
2)访问 http://localhost:8100/status
有内容显示
成功之后启动
appium ,start inspector session,startSession
。写入如下:
9.
可以运行写好的测试脚本
遇到其他问题:
1.
需要使用收费的开发者帐户编译
WebDriverAgentRunner,其中的bundle identifier自定义可唯一标识就行
(地址: https://developer.apple.com/account/
)
2
.
证书冲突,将
BuildSettings
里的
code singing identity
设置成
iPhone Develpoer
,解决
3.
编译时发现
ServerURLHere->http://10.242.35.210:0
,端口号为
0
Log
如下:
background with task ID 1
Test Suite 'All tests' started at 2018-07-03 14:02:32.203
Test Suite 'WebDriverAgentRunner.xctest' started at 2018-07-03 14:02:32.206
Test Suite 'UITestingUITests' started at 2018-07-03 14:02:32.208
Test Case '-[UITestingUITests testRunner]' started.
t = 0.01s Start Test at 2018-07-03 14:02:32.214
t = 0.01s Set Up
2018-07-03 14:02:32.279721+0800 WebDriverAgentRunner-Runner[3133:267743] Built at Jul 3 2018 13:59:19
2018-07-03 14:02:32.399746+0800 WebDriverAgentRunner-Runner[3133:267743] ServerURLHere->http://10.242.35.210:0<-ServerURLHere
解决方法有两种:
1)端口参数指定,增加USE_PORT=8100
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=udid’ USE_PORT=8100 test
2) 如果还是无法解决,Xcode打开WebDriverAgentLib-Routing-FBWebServer.m下的端口
4.xcodebuild failed with code 65
command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: "xcodebuild failed with code 65". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md
. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
解决方法:Desired Capabilities中加入xcodeOrgId,也就是teamid。需要填写
xcodeOrgId——-teamid,可以让开发查看,或者登录 https://developer.apple.com/account
,membership中的TeamID
到此,真机的测试环境已经跑通,有什么写的不对的地方欢迎大家指正。