1.macOS相關庫安裝
- libimobiledevice
> brew install libimobiledevice
使用本機與蘋果iOS設備的服務進行通信的庫。
- ideviceinstaller
brew install ideviceinstaller
獲取設備udid、安裝app、卸載app、獲取bundleid
- carthage
> brew install carthage
第三方庫管理工具。
- ios-deploy
> brew install ios-deploy
ios-deploy 不依賴於XCODE,進行安裝和調試IOS應用程序。
- node & npm
> brew install node
> brew install npm
- appium-doctor
npm install -g appium-doctor
- 驗證appium環境
> appium-doctor
info AppiumDoctor Appium Doctor v.1.11.0
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Node version is 10.15.1
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode-beta.app/Contents/Developer
info AppiumDoctor ✔ Xcode Command Line Tools are installed in: /Applications/Xcode-beta.app/Contents/Developer
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
info AppiumDoctor ✔ Carthage was found at: /usr/local/bin/carthage. Installed version is: 0.33.0
info AppiumDoctor ✔ HOME is set to: /Users/tech
...
2.XCode
Xcode 是iOS開發環境,可以到app store 下載安裝。
Xcode 的安裝需要macOS升級到最新的版本,如果你的系統不是最新版本需要升級。
WebDriverAgent
在模擬器中運行的用於iOS的WebDriver服務器。
https://github.com/appium/WebDriverAgent
該項目由facebook開發,appium拉了個分支來維護,更新上超過了facebook,所以我們用appium的分支。
-
通過git clone 將項目克隆下來。
-
進入項目目錄執行shell腳本:
../WebDriverAgent> ./Scripts/bootstrap.sh
- 通過xcode導入WebDriverAgent 項目
- 找到build Settings ---> packaging---> Product Bundle Identifier 選項。將值修改為唯一識別的字符串。
- Build Phases ---> Copy frameworks ---> 檢查框架。
- RoutingHTTPServer.framework
- YYCache.framework
如果沒有這兩個框架,點擊下方加號+添加。
3.iPhone
准備一台iPhone手機,通過數據線與PC進行連接。
1.選擇連接的手機
2.菜單欄:product --> Scheme --> WebDriverAgentRunner
3.菜單欄:Product---> Test
4.在iPhone手機上打開設置:通用--> 描述文件與設備管理--> 開發者App ,設置Apple Development xxxxx 在此iPhone上受信任。
5.檢查日志是否有錯誤。
4.iproxy
安裝 usbmuxd,他自帶了iproxy小工具,iproxy將設備上的端口映射到電腦上的某個端口。
> brew install usbmuxd
> iproxy 8100 8100
5.開始測試
終於可以開始測試了,你有幾種選擇。
我選 openatx/facebook-wda,因為它更加簡單。
安裝:
pip3 install -U facebook-wda
測試腳本:
import wda
c = wda.Client('http://localhost:8100')
print(c.status())
結果:
{'message': 'WebDriverAgent is ready to accept commands', 'state': 'success', 'os': {'name': 'iOS', 'version': '13.4', 'sdkVersion': '13.4'}, 'ios': {'simulatorVersion': '13.4', 'ip': '192.168.1.8'}, 'ready': True, 'build': {'time': 'Mar 28 2020 23:01:36', 'productBundleIdentifier': 'com.facebook.WebDriverAgentRunner'}, 'sessionId': 'F951380E-7219-4EA9-84FC-CC8BE78A12F8'}
好了,可以開始你的iOS自動化測試了。