【Mac系统】之IOS自动化:WebDriverAgent安装

汇总:

非常感谢:

codeskyblue的文章:《ATX ATX 文档 - iOS 真机如何安装 WebDriverAgent》 

Nuanyang2333的文章:《课前准备——WebDriverAgent 安装

====================================================

以及其他暂时还没用到的文章:

yxys01的文章:《WebDriverAgent 天坑记

wonderfei的文章:《基于Facebook-WDA的iOS-UI自动化测试

Winnie_zi 的文章:《iOS 自动化—wda 搭建流程

 

一、前提准备条件:

环境配置

  1. MacOs
  2. Xcode(建议更新为最新版本)
  3. npm
  4. carthage

 

安装npm和Carthage


# 安装 node
brew install node
# 查看npm版本
npm -v

6.2.0

  # 安装Carthage:

brew install Carthage

# 如果只是更新请输入
brew upgrade carthage

从github中克隆WebDriverAgent项目

cd到自定义的文件夹下下载:

git clone https://github.com/facebook/WebDriverAgent
Cloning into ‘WebDriverAgent‘...
remote: Enumerating objects: 18281, done.
remote: Total 18281 (delta 0), reused 0 (delta 0), pack-reused 18281
Receiving objects: 100% (18281/18281), 15.61 MiB | 52.00 KiB/s, done.
Resolving deltas: 100% (6909/6909), done.

*运行初始化脚本

首先需要先进入到WebDriverAgent项目的根目录下

# 进入到WDA 根目录
cd WebDriverAgent/

# 运行初始化脚本
./Scripts/bootstrap.sh

 

Fetching dependencies
Please update to the latest Carthage version: 0.31.1. You currently are on 0.30.1
*** Checking out RoutingHTTPServer at "v1.0.1"
*** Cloning RoutingHTTPServer
*** xcodebuild output can be found in /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/carthage-xcodebuild.RROZOv.log
*** Downloading RoutingHTTPServer.framework binary at "v1.0.1"
Building Inspector
Creating bundle directory...
Fetching Inspector dependencies...
npm WARN deprecated css-list@0.1.3: Deprecated.
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated browserslist@0.4.0: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.

> fsevents@1.2.4 install /Users/zhan/Desktop/mine/Stu资料/Git/WebDriverAgent/Inspector/node_modules/fsevents
> node install

[fsevents] Success: "/Users/zhan/Desktop/mine/Stu资料/Git/WebDriverAgent/Inspector/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN react-dom@15.6.2 requires a peer of react@^15.6.2 but none is installed. You must install peer dependencies yourself.
npm WARN web-driver-inspector@1.0.0 No repository field.

added 759 packages from 536 contributors and audited 2620 packages in 69.318s
found 9 vulnerabilities (4 low, 4 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
Validating Inspector
Building Inspector...

> web-driver-inspector@1.0.0 build /Users/zhan/Desktop/mine/Stu资料/Git/WebDriverAgent/Inspector
> webpack --progress --colors

Hash: 0acdc7e8b3b0d143afc5  
Version: webpack 1.15.0
Time: 7085ms
       Asset    Size  Chunks             Chunk Names
inspector.js  862 kB       0  [emitted]  main
   [0] multi main 28 bytes {0} [built]
    + 226 hidden modules
Done

二、证书配置

1、Xcode打开WebDriverAgent目录下的WebDriverAgent.xcodeproj文件。

(1)按照下面图的步骤依次执行点击,先配置WebDriverAgentLib

 【Mac系统】之IOS自动化:WebDriverAgent安装

(2)按照下面图的步骤依次执行点击,再配置WebDriverAgentRunner

【Mac系统】之IOS自动化:WebDriverAgent安装

但是会提示问题:

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设置中,找到Packaging中的选项,将其内容修改为唯一识别的字符串,如下图所示

【Mac系统】之IOS自动化:WebDriverAgent安装

【Mac系统】之IOS自动化:WebDriverAgent安装

 

不报错了:

【Mac系统】之IOS自动化:WebDriverAgent安装

三、运行与测试

1、iphone手机连接Mac,并添加信任

2、选择Product->Destination->你的设备

【Mac系统】之IOS自动化:WebDriverAgent安装

 

3、选择Product->Scheme->WebDriverAgentRunner

【Mac系统】之IOS自动化:WebDriverAgent安装

 然后进行运行,Product中选择test

【Mac系统】之IOS自动化:WebDriverAgent安装

 

 运行后会提示输入密码:

【Mac系统】之IOS自动化:WebDriverAgent安装 

一直输入密码,直到它不提示为止,此密码应该为登录密码。

参考文章:《codesign 想要访问您的钥匙串中的密钥

 

但是,运行后创建成功,但是证书有问题。

【Mac系统】之IOS自动化:WebDriverAgent安装

 

The certificate used to sign "WebDriverAgentRunner-Runner" has either expired or has been revoked. An updated certificate is required to sign and install the application.

 

用于签署“WebDriverAgentRunner Runner”的证书已过期或被撤销。需要更新的证书来签署和安装应用程序。

 

 打开“钥匙串访问”,查看【我的证书】得知,原来是证书过期了。

【Mac系统】之IOS自动化:WebDriverAgent安装

 右键删除此证书。

【Mac系统】之IOS自动化:WebDriverAgent安装

 

 

删除证书后 ,再重新添加,如下图

【Mac系统】之IOS自动化:WebDriverAgent安装

 

 再次运行Xcode,先删除之前的运行的,Product->Clean Build Folder

 【Mac系统】之IOS自动化:WebDriverAgent安装

 

此时,不出意外 WDA在手机中安装成功,并且下面控制台输出下面的效果。

打开控制台方法:选择view->Debug Area->Activate console打开底部控制台。

【Mac系统】之IOS自动化:WebDriverAgent安装

 

 然后控制台会输出IP地址和端口,例如:http://192.168.0.0:8100/status,输入在浏览器中,

确认WDA是否运行成功。如果出现一串JSON输出,说明WDA安装成功了。

但是可能会出不来,

# 使用--HEAD安装最新版本
$ brew install libimobiledevice --HEAD
$ iproxy 8100 8100

 但是会提示你需要更新:

Warning: libimobiledevice HEAD-26373b3_2 is already installed and up-to-date
To reinstall HEAD_3, run `brew reinstall libimobiledevice`
$ brew reinstall libimobiledevice

更新后:

# 运行命令后会显示如下:
$ iproxy 8100 8100
waiting for connection

参考文章:《【转自Testerhome】iOS 真机如何安装 WebDriverAgent

此时浏览器输入:http://localhost:8100/status ,确认WDA是否运行成功。

 【Mac系统】之IOS自动化:WebDriverAgent安装

 

 而inspector的地址是http://localhost:8100/inspector, inspector是用来查看UI的图层,方便写测试脚本用的

【Mac系统】之IOS自动化:WebDriverAgent安装

 

 

 

 

 

 

 

 

 

 

【Mac系统】之IOS自动化:WebDriverAgent安装

上一篇:windows10移动热点打开后手机不能上网


下一篇:android -------- MVP+DataBinding 的使用