1、WDA介紹
WebDriverAgent 在 iOS 端實現了一個 WebDriver server ,借助這個 server 我們可以遠程控制 iOS 設備。你可以啟動、殺死應用,點擊、滾動視圖,或者確定頁面展示是否正確。
facebook的WDA在iOS 10 時代蘋果已經廢棄了,目前依然在更新的是Appium官方的WDA,官方鏈接如下:https://github.com/appium/WebDriverAgent,安裝配置和facebook類似,配置好簽名證書即可,不需要修改代碼,也不需要修改Bundle ID.如果想查看iOS的應用界面,安裝使用Appium的Inspector即可
2、部署環境
OS: 11.6
Xcode:13 (需要系統更新最新才能在appstore下載xcode)
3、安裝步驟
1、安裝基礎依賴
brew install git
brew install carthage
2、下載WDA
安裝appiium就帶有WebDriverAgent (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent)
3、執行bootstrap.sh
./Scripts/bootstrap.sh
ERROR in ./js/app.js
Module parse failed: /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/js/app.js Unexpected token (67:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (67:6)
at Parser.pp$4.raise (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
解決方法:cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/webpack.config.js
webpack.config.js 文件里去掉 exclude: /node_modules/
(忽略node_modules)
修改前:
module: { loaders: [ { test: /\.js?$/, loaders: ['babel-loader'], exclude: /node_modules/ }, { test: /\.js?$/, loaders: ['babel-loader'] }, { test: /\.css?$/, loader: 'style-loader!css-loader' }, ] },
修改后:
loaders: [ { test: /\.js?$/, loaders: ['babel-loader'] }, { test: /\.css?$/, loader: 'style-loader!css-loader' }, ]
重新執行 ./Scripts/bootstrap.sh
4、打開WebDriverAgent工程配置
終端cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent,通過open WebDriverAgent.xcodeproj(xcdoe打開方式)
1、ios自動化所需的WebDriverAgent需要簽名產生,找開發要p12證書和描述文件.mobileprovision
1、點擊p12輸入密碼之后,要先選中登陸,導入p12文件即可
2、雙擊.mobileprovision描述文件,會自動安裝到xcode中
2、選擇WebDriverAgent進入
3、除了tv_os的target都進行重簽配置,如下圖所示修改配置
WebDriverAgentLib 如下圖:
WebDriverAgentRunner 配置如下圖:
檢查WebDriverAgentRunner-signing&Capabilities
4、選擇product,scheme選擇WebDriverRunner
5、構建項目build
選擇iphone
點擊build
6、檢測是否安裝wda成功
由於國內手機設置需要轉發下端口,命令行執行:iproxy 8300 8100
然后再瀏覽器里請求:http://localhost:8300/,如果返回一串json字符,那么WDA安裝成功了
http://localhost:8300/status可以查看當前設備的狀態,獲取與wda通信session id
http://localhost:8300/inspector 打開WDA 的inspector,在該界面點擊home則手機返回主頁面