1. 程式人生 > >【Mac系統】之IOS自動化:WebDriverAgent安裝

【Mac系統】之IOS自動化:WebDriverAgent安裝

自動化測試 自動化 8.0 ram frame ava lan neu rip

匯總:

非常感謝:

①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[email protected]: 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.

> [email protected] 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[email protected] requires a peer of react@^15.6.2 but none is installed. You must install peer dependencies yourself.
npm WARN web[email protected] 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...

> [email protected] 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

技術分享圖片

(2)按照下面圖的步驟依次執行點擊,再配置WebDriverAgentRunner

技術分享圖片

但是會提示問題:

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中的選項,將其內容修改為唯一識別的字符串,如下圖所示

技術分享圖片

技術分享圖片

不報錯了:

技術分享圖片

三、運行與測試

1、iphone手機連接Mac,並添加信任

2、選擇Product->Destination->你的設備

技術分享圖片

3、選擇Product->Scheme->WebDriverAgentRunner

技術分享圖片

然後進行運行,Product中選擇test

技術分享圖片

運行後會提示輸入密碼:

技術分享圖片

一直輸入密碼,直到它不提示為止,此密碼應該為登錄密碼。

參考文章:《codesign 想要訪問您的鑰匙串中的密鑰》

但是,運行後創建成功,但是證書有問題。

技術分享圖片

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”的證書已過期或被撤銷。需要更新的證書來簽署和安裝應用程序。

打開“鑰匙串訪問”,查看【我的證書】得知,原來是證書過期了。

技術分享圖片

右鍵刪除此證書。

技術分享圖片

刪除證書後 ,再重新添加,如下圖

技術分享圖片

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

技術分享圖片

此時,不出意外 WDA在手機中安裝成功,並且下面控制臺輸出下面的效果。

打開控制臺方法:選擇view->Debug Area->Activate console打開底部控制臺。

技術分享圖片

然後控制臺會輸出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是否運行成功。

技術分享圖片

而inspector的地址是http://localhost:8100/inspector, inspector是用來查看UI的圖層,方便寫測試腳本用的

技術分享圖片

【Mac系統】之IOS自動化:WebDriverAgent安裝