使用Appium進(jìn)行iOS的真機(jī)自動(dòng)化測試

  • 環(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)境正常,如圖


6C7309F4-4054-463B-85DF-88D4C44DE110.png
  • 更新Appium中的WebDriverAgent
    1.到WebDriverAgent下載最新版本的WebDriverAgent
    2.進(jìn)入下載后的WebDriverAgent文件路徑
cd WebDriverAgent

3.執(zhí)行

./Scripts/bootstrap.sh

4.直接用Xcode打開WebDriverAgent.xcodeproj文件
5.配置WebDriverAgentLibWebDriverAgentRunner的證書

1F9C4306-5A54-4C1F-9848-726F4C919CB1.png

6.選擇目標(biāo)設(shè)備
2581954-4f960a3ed6235a89.png

7.選擇 WebDriverAgentRunner
2581954-68186c0e0dbbf26c.png

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

一切正常的話,手機(jī)/模擬器上會(huì)出現(xiàn)一個(gè)無圖標(biāo)的 WebDriverAgent 應(yīng)用,啟動(dòng)之后,馬上又返回到桌面。

此時(shí)控制臺(tái)界面可以看到設(shè)備的 IP 地址:


FBBE4F78-E535-4D4E-AF5E-779BABA6DD0D.png

通過上面給出的 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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容