說在前面的話
之前公司需要搭建一款Appium的ios測試環境,網上的也有不少相關教程,但是都基本都是早期的版本,此次將會使用最新版的·Appium Desktop 1.15.0
來總結此次搭建途中遇到的坑,希望可以幫助後面需要搭建此環境的同學們。
安裝步驟
- Appium Desktop
截止今天最新版的版本是1.15.0
,Appium-Desktop 如下圖所示:
下載mac os
平臺的 appium,然後進行一路Next
安裝即可。 - Xcode:10.3
這裏博主的mac系統版本爲10.14.6
如下圖所示:
這裏不建議使用最新版的mac catalina
,筆者在此係統上遇到xcode編譯項目失敗的問題,而此版本的macos的xcode不存在此問題,因此下載此版本對應的Xcode版本即可,首先進入鏈接https://developer.apple.com/download/more/ 進入頁面並使用apple id
登錄後可以看到如下畫面:
找到並下載Xcode 10.3
以及對應版本的Command line Tools for Xcode
如下圖所示:
下載完畢後,先將Xcode 10.3.xip
解壓後的程序移動到mac的應用程序目錄即可,然後在安裝dmg文件。 - JDK:1.8
關於JDK安裝可以參考我之前寫過的一篇文章JDK安裝教程 進行安裝即可,然後配置一下JDK的環境變量即可,如下圖所示:
- brew
brew 是 Mac 下的一個包管理工具,類似於 centos 下的 yum,可以進行軟件的安裝、更新以及卸載等操作。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝過程如下圖所示:
安裝後查看安裝brew版本:
- Node
AppiumDesktop
是用Node.js
編寫的服務器,所以需要安裝node。若你的電腦安裝有brew
環境直接輸入下面命令行即可進行node
的安裝。
brew install node
完成執行node -v,查看安裝node版本:
其中 NPM
是Node.js
包管理工具,下載安裝Node.js
會自動安裝NPM
,可以查看一下NPM
的版本:
- ruby
一般macos自帶ruby,如果沒有請安裝ruby環境,查看ruby的環境版本:
- git
由於許多組件下載都需要git進行相關組件下載,這裏也需要進行git的安裝
brew install git
- carthage
類似於 java 的 maven,項目依賴管理,主要是 WebDriverAgent 使用
brew install carthage
- npm appium doctor
這個是檢查Appium環境的一套組件,終端執行下面命令:
sudo npm install appium-doctor -g
安裝完成後,終端輸入下面命令以檢查appium所需要的環境是否齊全。
appium-doctor
這裏有報錯提升是由於安裝是基於IOS版本的,所以android的SDK環境暫未下載。需要注意的是:網上有很多關於Face book
的WebDriverAgent
項目,但是這些項目已經很老且很久沒有維護,而且存在很多的問題。這裏推薦使用Appium Desktop
自帶的WebDriverAgent
項目即可,打開Appium-Desktop的WebDriverAgent
項目的路徑
目錄如下所示:
/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent
將目錄copy到桌面。進入WebDriverAgent
項目的根目錄下執行下面命令:
# 進入到WDA 根目錄
cd WebDriverAgent/
# 運行初始化腳本
./Scripts/bootstrap.sh
- ideviceinstaller
brew install ideviceinstaller
- ios-deploy
-ios-deploy是一個終端安裝和調試iPhone應用的是第三方開源庫
npm install -g ios-deploy
查看連接的設備:
ios-deploy -c
運行WebDriverAgent
上面的環境搭建好後,打開桌面的appium-webdriveragent
的WebDriverAgent.xcodeproj
文件
打開後需要做的就是配置Xcode
的account
添加你的apple Id
,可以通過下面操作進行配置如下圖所示:
- 打開首選項
- 添加apple id
配置這個原因是WebDriverAgent需要配置個人證書,通過我們的apple Id即可以生成。 - 配置WebDriverAgentLib
- 配置WebDriverRunner
但是有可能會提示問題:
The app ID "com.facebook.WebDriverAgentRunner" cannot be registered
to your development team. Change your bundle identifier
to a unique string to try again.
解決方法:WebDriverAgentRunner -> Build Settings設置中,找到Packaging中的選項,將其內容修改爲唯一識別的字符串。
修改完畢後就不報錯了。
- iphone連接設置
選擇Proudct->Test
如下圖所示:
注意問題:This iPhone 7 (Model 1660, 1778, 1779, 1780) is running iOS 13.1.2 (17A860), which may not be supported by this version of Xcode.
如下圖所示:
github下載相應版本IOS設備支持 IOS設備支持地址 如下圖所示:
下載完成後將安裝包解壓到路徑
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
下,如下圖所示:
重啓Xcode,再次運行Product->Test
運行完成可能會報以下的錯誤:
This application’s application-identifier entitlement does not match that of the installed application. These values must match for an upgrade to be allowed.
這是因爲手機已經存在了一個WebDriverRunner
,刪除了app重新在運行就好,再次運行就會報以下錯誤。
Verify the Developer App certificate for your account is trusted on your device. Open Settings on iPhone and navigate to General -> Device Management, then select your Developer App certificate to trust it.Internal launch error: process launch failed: Security
解決方法:設置=》通用=》設備管理=》開發者應用=》驗證應用 如下圖所示:
點擊信任即可如下圖所示:
先刪除之前的運行的 Product->Clean Build Folder, 再次運行Product->Test。
- 安裝libimobiledevice
brew install libimobiledevice --HEAD
安裝後可能報下面的這個錯誤:
原因是:由於系統要求的libusbmuxd 版本和所要安裝的版本不一致的問題導致的,可使用下面命令進行解決。
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
打開控制檯方法:選擇view->Debug Area->Activate console打開底部控制檯。然後控制檯會輸出IP地址和端口,例如:http://127.0.0.1:8100/status,輸入在瀏覽器中,確認WDA是否運行成功,頁面刷新出不來,再次輸入下面命令開啓代理:
iproxy 8100 8100
然後重新刷新瀏覽器如下圖所示:
配置Appium-Desktop
- 配置JAVA_HOME
點擊Edit Configuration
配置以下環境變量,如下圖所示:
- 開啓Inspector Session
- 允許未授權認證
通用配置對象如下圖所示:
需要注意的是其中獲取iphone的uuid,在終端輸入:idevice_id -l
即可獲取,而bundleId可以通過輸入命令:ideviceinstaller -l
出現如下圖列表:
更多配置請參考:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
配置完成後點擊Start Session
的時候報端口占用的錯誤如下圖所示:
解決方法:重啓appium-desktop軟件編輯修改ios的WebDriverAgent的端口號入下圖所示:
設置完成後在重新Start Session
如果可以看到下面的頁面就證明安裝已經成功。