Appium+Python3+iOS真機環境搭建 (轉載並更新)
Appium 是一個自動化測試開源工具,支持 iOS 平臺和 Android 平臺上的原生應用,web 應用和混合應用。
本次環境配置相關:
macOS:10.12 (Sirerra) -> 10.14.3 (Mojave)
Appium-desktop:1.10.0.dmg
Xcode:8 -> 10.1
一、環境升級
說明:原來系統 mac os Sierra (10.12) 按照環境配置(二)運行時,提示系統版本過低,Xcode版本過低。
1. 升級 Mac OS,鏈接:https://support.apple.com/zh-cn/macos/high-sierra (選擇了最新的 Mojave)
2. 升級 Xcode,APP Store 選擇最新版本更新。
二、環境配置
1、 安裝homebrew:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、 安裝libimobiledevice:
$ brew install libimobiledevice --HEAD
Requested ‘libusbmuxd >= 1.1.0‘ but version of libusbmuxd is 1.0.10解決辦法
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
3、 安裝carthage:
$ brew install carthage
4、安裝node:
$ brew install node
5、安裝npm:
$ brew install npm
安裝cnpm:國內直接用npm下載安裝會有好多網絡問題,安裝淘寶的cnpm要比npm好用,https://npm.taobao.org/
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
Note: 如果下面涉及 npm 操作有問題時,可改用 cnpm
6、安裝ios-deploy:
$ npm install -g ios-deploy
select: error: tool ‘xcodebuild‘ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools‘ is a command line tools instance
以上錯誤是因為安裝了 xcode , 但並不是系統默認的位置, 所以可以使用以下命令把 xcode 的路徑修改為你安裝的位置即可
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
8、安裝xcpretty:
$ gem install xcpretty
9、安裝appium,appium-doctor
進入官網,下載Appium-1.10.0.dmg,安裝即可。
10、使用appium-doctor 檢查Appium iOS環境環境
appium-doctor --ios
二、安裝WebDriverAgent
1、下載 facebook 的 WebDriverAgent,進入 https://github.com/facebook/WebDriverAgent/,下載
2、進入appium安裝目錄下 Downloads,將下載的 WebDriverAgent-master,重新命名為 WebDriverAgent
3、在 Downloads/WebDriverAgent目錄下執行以下命令
$ cd Downloads/WebDriverAgent
$ mkdir -p Resources/WebDriverAgent.bundle
$ sh ./Scripts/bootstrap.sh
4. 將Downloads/WebDriverAgent 文件夾替換掉 Appium 安裝目錄下的 WebDriverAgent
4.1 進入“訪達”,/Applications/Appium.app,右鍵 “顯示包內容”,
具體路徑為 /Applications/Appium.app/Contents/Resources/app/node_modules/appium-xcuitest-driver
4.2 將原來的 WebDriverAgent 更名為 WebDriverAgent2
4.3 將 Downloads/WebDriverAgent 復制過來
5、編譯WebDriverAgent.xcodeproj
在/Applications/Appium.app/Contents/Resources/app/node_modules/appium-xcuitest-driver/WebDriverAgent,選擇 WebDriverAgent.xcodeproj,使用 Xcode打開
註意:進入項目後要編輯一些內容,請無比按照步驟全部修改。
1、Project WebDriverAgent 下面的 Target 涉及到的 文件的 Bundle Identifier 需要全部重新命名。(圖片 mark "4",並且 所有Identifier註意保持一致!!)
修改規則:com.facebook.xx.xx, 將前面的 com.facebook 重新更名為 自己要測試的 app 包名,並且後面部分不同
2、TARGETS->WebDriverAgentLib的修改為例:
2.1,修改 Build Settings 為例:修改 Product Bundle Identifier 值的 com.facebook.wda.lib 為 com.gece.smartinvest.wda.lib
2.2,General 的 Bundle Identifier 值的 com.facebook.wda.lib 為 com.gece.smartinvest.wda.lib
2.3,勾選 Signing,選擇 “Automatically manage signing”,並且 選擇使用個人的證書。(經使用,可以使用 Apple ID,不需要開發者賬號)
3. 依次 修改 WebDriverAgentRunner -> UnitTests -> IntegrationTests_1 -> IntegrationTests_2 ->IntegrationTests_3 -> IntegrationAPP
4、Device選擇已連接的測試機
5、點擊build按鈕來測試,按照步驟設置後,可build succeeded~
6、測試機上安裝證書,執行以下命令:
$ xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=測試機的udid‘ test
Notes: 查詢 udid, 可以通過 itunes 連接 手機 查找
如果沒有報錯證明安裝成功,同時手機上會安裝一個WebDriverAgent軟件。需要在手機設置->通用->設備管理->信任開發者。如下圖: image.png
三、Appium Client端
Appium Client有Ruby,Python,Java三個版本,可自行選擇自己喜歡的安裝即可,本次只針對Python版安裝:
pip install Appium-Python-Client
Appium+Python3+iOS真機環境搭建 (轉載並更新)