環(huán)境搭建
Xcode
appium安裝依賴工具包
brew install node
brew install npm
brew install --HEAD ideviceinstaller
brew install --HEAD libimobiledevice
brew install ios-deploy
brew install carthage
npm install -g appium-doctor
在終端輸入
appium-doctor
驗(yàn)證所有依賴是否安裝成功,都是打鉤狀態(tài)就證明環(huán)境正常,如圖

- 更新Appium中的WebDriverAgent
1.到WebDriverAgent下載最新版本的WebDriverAgent
2.進(jìn)入下載后的WebDriverAgent文件路徑
cd WebDriverAgent
3.執(zhí)行
./Scripts/bootstrap.sh
4.直接用Xcode打開WebDriverAgent.xcodeproj文件
5.配置WebDriverAgentLib和WebDriverAgentRunner的證書

6.選擇目標(biāo)設(shè)備

7.選擇 WebDriverAgentRunner

8.最后運(yùn)行 Product -> Test:

一切正常的話,手機(jī)/模擬器上會(huì)出現(xiàn)一個(gè)無圖標(biāo)的 WebDriverAgent 應(yīng)用,啟動(dòng)之后,馬上又返回到桌面。
此時(shí)控制臺(tái)界面可以看到設(shè)備的 IP 地址:

通過上面給出的 IP地址 和端口,加上/status合成一個(gè)url地址。例如 [http://192.168.3.26:8100/status],然后瀏覽器打開。如果出現(xiàn)一串 JSON 輸出,說明 WDA 安裝成功了。
如果連接的是真機(jī),則有可能會(huì)打不開。我們需要做一下端口轉(zhuǎn)發(fā)。
iproxy 8100 8100
此時(shí)在瀏覽器中打開鏈接http://localhost:8100/status查看,顯示:
{
"value" : {
"message" : "WebDriverAgent is ready to accept commands",
"state" : "success",
"os" : {
"testmanagerdVersion" : 28,
"name" : "iOS",
"sdkVersion" : "13.4",
"version" : "13.4"
},
"ios" : {
"ip" : "192.168.3.26"
},
"ready" : true,
"build" : {
"time" : "Sep 14 2020 14:26:07",
"productBundleIdentifier" : "com.facebook.WebDriverAgentRunner"
}
},
"sessionId" : "CD0C278F-B8AB-403B-9094-7A18FF70F9B9"
}
-
關(guān)掉端口轉(zhuǎn)發(fā),不要停止xcode運(yùn)行,打開appium,做如下配置:
5F721C5F-0469-41C1-AC72-13F322D4DE81.png
"udid": "",#設(shè)備id
"platformName": "iOS",
"deviceName": "iphone11",#手機(jī)型號
"bundleId": "",#APP id 可通過ideviceinstaller -l查看
"platformVersion": "11.4",#系統(tǒng)版本
"xcodeOrgId": "",#開發(fā)者賬號id
"xcodeSigningId": "iPhone Developer",
"automationName": "XCUITest"
我已經(jīng)在手機(jī)上裝好了被測應(yīng)用,若還未安裝,需通過appName指定安裝包路徑。點(diǎn)擊右下角Start Session,
-
成功啟動(dòng)后,會(huì)出現(xiàn)這個(gè)編輯界面,可以開始自動(dòng)化測試的步驟設(shè)置啦
IMG_4022.JPG
問題匯總
1.報(bào)錯(cuò)
WebDriverAgent.xcodeproj Building for iOS, but the embedded framework 'RoutingHTTPServer.framework' was built for iOS + iOS Simulator.
解決:
WebDriverAgent -> Build Settings -> Build Options -> Validate Workspace = Yes.
- 查看iPhone手機(jī)上app的bundleid
ideviceinstaller -l
- 查看mac上的模擬器或連接的iOS設(shè)備
instruments -s devices
遇到的問題
1.執(zhí)行./Scripts/bootstrap.sh后報(bào)錯(cuò)
A shell task (/usr/bin/env git clone --bare --quiet https://github.com/marekcirkos/RoutingHTTPServer.git /Users/galaxy/Library/Caches/org.carthage.CarthageKit/dependencies/RoutingHTTPServer) failed with exit code 128:
fatal: unable to access 'https://github.com/marekcirkos/RoutingHTTPServer.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
原因不詳,已解決
xcode-select --print-path
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
2.xcode運(yùn)行報(bào)錯(cuò)
error: Building for iOS, but the linked and embedded framework 'RoutingHTTPServer.framework' was built for iOS + iOS Simulator. (in target 'WebDriverAgentLib' from project 'WebDriverAgent')
解決
WebDriverAgent
-> Build Settings
-> Build Options
-> Validate Workspace = Yes for each target of the workspace
