[个人笔记] MAC 下安装WebDriverAgent

参考:https://testerhome.com/topics/7220

下载WebDriverAgent源码:

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

运行初始化脚本:

./Scripts/bootstrap.sh

该脚本会使用Carthage下载所有的依赖,使用npm打包相应的js文件。

执行这个脚本期间,会因为有些包没有安装而中断:

brew install carthage

brew install npm

WebDriverAgentRunner:

报错1:

The app ID "com.facebook.WebDriverAgentRunner" cannot be registered to your development team. Change your bundle identifier to a unique string to try again.


报这个错是因为WebDriverAgentRunner -> Build Settings -> Build Settings -> Packaging -> Product Bundle Identifier 要改成唯一可识别字符串
报错2:

"Failed to create provisioning profile.There are no devices registered in your account on the developer website. Plug in and select a device to have Xcode register it."

No profiles for 'com.rockets.provenance' were found Xcode couldn't find any iOS App Development provisioning profiles matching 'com.rockets.provenance'.

报这个错是因为没有接入相关的设备到MAC上,只要设备接入,并通过XCode菜单:Product->Destnation->"Select Devices"选中要连接的设备就行。

XCode:
Product->Destination->”Select your iphone”
Product->Scheme->”Select WebDriverAgentRunner”
Product -> Test

注意:运行Test之前,手机先解锁再通过USB线连接到电脑。

运行完”Test”,如果遇到这个报错:

error: failed to launch '/private/var/containers/Bundle/Application/BA42CC5E-D4BF-486F-A45D-4D172E0AFFA2/WebDriverAgentRunner-Runner.app' -- Verify the Developer App certificate for your account is trusted on your device. Open Settings on "iPhone name" and navigate to General -> Device Management, then select your Developer App certificate to trust it.

则需要在手机的通用->设备管理中,选择信任开发者证书。

测试运行期间,会在iphone的桌面上生成一个”WebDriverAgentRunner-Runner”的图标,生成类似下面格式的日志信息:

2018-03-12 15:28:44.099884+0800 WebDriverAgentRunner-Runner[1097:323808] +[CATransaction synchronize] called within transaction
2018-03-12 15:28:44.160403+0800 WebDriverAgentRunner-Runner[1097:323808] Running tests...
2018-03-12 15:28:46.791644+0800 WebDriverAgentRunner-Runner[1097:323808] Continuing to run tests in the background with task ID 1
2018-03-12 15:29:17.746896+0800 WebDriverAgentRunner-Runner[1097:323808] Continuing to run tests in the background with task ID 4
Test Suite 'All tests' started at 2018-03-12 15:29:18.420
Test Suite 'WebDriverAgentRunner.xctest' started at 2018-03-12 15:29:18.421
Test Suite 'UITestingUITests' started at 2018-03-12 15:29:18.422
Test Case '-[UITestingUITests testRunner]' started.
 t = 0.00s Start Test at 2018-03-12 15:29:18.423
 t = 0.00s Set Up
2018-03-12 15:29:18.440098+0800 WebDriverAgentRunner-Runner[1097:323808] Built at Mar 1 2018 18:50:16
2018-03-12 15:29:18.465613+0800 WebDriverAgentRunner-Runner[1097:323808] ServerURLHere->http://169.254.209.183:8100<-ServerURLHere

这里,浏览器直接访问:http://169.254.209.183:8100 会一直超时,无法成功访问。解决方案如下:

端口转发:
原因:有些国产的iPhone机器通过手机的IP和端口还不能访问,此时需要将手机的端口转发到Mac上:
配置方法:
brew install libimobiledevice
brew install ideviceinstaller
$ iproxy 8100 8100
使用iproxy --help 可以查到更具体的用法。 这时通过访问http://localhost:8100/status确认WDA是否运行成功。
而inspector的地址是http://localhost:8100/inspector, inspector是用来查看UI的图层,方便写测试脚本用的。

运行微信跳一跳AI程序的话,还要安装如下组件:
pip install opencv-python
pip install facebook-wda

附:
苹果开发账户相关配置:
http://help.apple.com/developer-account/#/dev40df0d9fa

libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备。

通过人工智能深度学习得到的模型来跑微信游戏跳一跳 原帖:
https://zhuanlan.zhihu.com/p/32636329