本人的環境搭建前的准備,MAC電腦一台(macOS Mojave 10.14.0及以上),Xcode 10.0及以上 ,自己注冊的一個Apple ID 賬戶,必須你的電腦能連接互聯網,最好不要用公司的網絡,限制太多,容易掉坑里。
1.安裝Homebrew
安裝
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
卸載
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
對/usr/local 目錄下的文件讀寫進行root用戶授權:
sudo chown -R $USER /usr/local
2.安裝 libimobiledevice (得先安裝Homebrew)
brew install libimobiledevice
其實,libimobiledevice又稱libiphone,是一個開源包,可以讓Linux支持連接iPhone/iPod Touch等iOS設備。
3.安裝 usbmuxd 以便於通過 USB 通道測試 iOS 真機,不需要測試真機則不用安裝
brew install usbmuxd
4.安裝 ideviceinstaller(真機安裝相關)
brew install ideviceinstaller
libimobiledevice中並不包含ipa的安裝命令,所以還需要安裝ideviceinstaller ,安裝 ideviceinstaller 用來給真機安裝 App。
5.安裝 carthage , WebDriverAgent編譯時需要的依賴包。
brew install carthage
6.安裝 node
(目的是安裝 npm)官方下載地址https://nodejs.org/en/download/,下載.pkg 文件安裝(LTS版本),推薦最好用Homebrew 的命令去安裝 ,
brew install node
7.安裝 iOS-deploy
npm install -g ios-deploy
iOS-deploy 是一個終端安裝和調試iPhone應用的是第三方開源庫
8.安裝 xcpretty
gem install xcpretty
xcpretty
是一個用 ruby 實現的工具,可以用 gem install xcpretty
來安裝,主要作用是為了美化 xcodebuild
那冗長而且惡心的log輸出
9. Appium 桌面端下載安裝(選擇 dmg 文件)下載,點擊安裝。
https://github.com/appium/appium-desktop/releases
--點擊安裝包
10.安裝 Appium doctor
npm install -g appium-doctor
--主要是方便用於檢查MAC電腦環境是否滿足Appium依賴配置
11 .運行命令,
Appium-doctor --ios
--這這個命令主要是為了檢查看MAC的appium ios依賴環境是否安裝好。
12.安裝 webpack
npm i -g webpack
--這個鬼東西,我也不知到啥東東,呵呵
13.安裝 wd
npm install -g wd --(-g表示全局安裝)
--這個鬼東西,我也不知到啥東東,呵呵
14.應用中如含有 WebView,請安裝 ios-webkit-debug-proxy
brew install ios-webkit-debug-proxy --調試H5頁面的用到的環境依賴
15.編譯並在手機安裝 WebDriverAgentRunner 驅動 APP
a. 在安裝完Appium Destop ,從 https://github.com/appium/WebDriverAgent 下載的WebDriverAgent文件夾 ,
b. terminer(終端工具) 在 WebDriverAgent 文件夾路徑下運行:
mkdir -p Resources/WebDriverAgent.bundle
sh ./Scripts/bootstrap.sh -d
等待幾分鍾下載依賴的包后進行編譯完。替換路徑/Application/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent 下的WebDriverAgent文件夾 。
c. 雙擊WebDriverAgent.xcodeproj打開此項目,在這里我們的目的就是更改一些配置,讓他能夠編譯成功,首先編譯之前你得有 ID賬號,並且登錄你的Xcode賬戶
配置開發證書等
接着編譯WebDriverAgentRunner
配置 runner 的證書信息
配置 setting 信息
d. 建立服務WebDriverAgent (手機和MAC都在同一個網段下,且都能連接外網)關閉Xcode,從終端terminer 進入WebDriverAgent目錄文件夾運行以下命令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真機的udid' test
如果終端出現以下信息,表示編譯 OK,
Testing failed:
Early unexpected exit, operation never finished bootstrapping - no restart will be attempted ** TEST FAILED **
這個是時候iphone多了一個WebDriverAgentRunner的app ,
我們在通用設置的描述文件里面信任我們的開發證書之后再次運行下的指令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真機的udid' test
如果出現以下信息,表示運行成功了:
Test Suite 'All tests' started at 2019-05-04 14:44:24.692
Test Suite 'WebDriverAgentRunner.xctest' started at 2019-05-04 14:44:24.695
Test Suite 'UITestingUITests' started at 2019-05-04 14:44:24.698
Test Case '-[UITestingUITests testRunner]' started.
t = 0.00s Start Test at 2019-05-04 14:44:24.703
t = 0.01s Set Up
2019-05-04 14:44:24.719508+0800 WebDriverAgentRunner-Runner[931:98387] Built at May 4 2019 14:43:43
2019-05-04 14:44:24.827130+0800 WebDriverAgentRunner-Runner[931:98387] ServerURLHere->http://192.168.119.105:8100<-ServerURLHer
e.打開終端terminer運行命令:
iproxy 8100 8100
如下:
f.
此時Google瀏覽器打開:
http://localhost:8100/status

看到這,此時appium的WDA環境配置成功了。
16.下載安裝python3與安裝常用的庫,
a. 從 https://www.python.org/downloads/下載python3.6.8 ,雙擊安裝python3.6.8(什么版本自己決定)
b. 進入終端輸入如下命令,設置環境變量:
sudo open ~/.bash_profile
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
alias python="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6" ---添加,設置別名
修改成功的標志是,重新打開終端,輸入Python,界面和python3一樣
c.安裝robotframework
pip install robotframework
d.終端輸入如下命令,安裝wxPython 安裝版本是4.04
pip install wxPython==4.0.4
e. 下載和安裝robotframework-ride , 地址 :https://github.com/HelioGuilherme66/RIDE/releases
環境配置要求:
sudo -H pip install -U -r https://github.com/HelioGuilherme66/RIDE/raw/release/requirements.txt
ride的版本:
sudo -H pip install -U https://github.com/HelioGuilherme66/RIDE/releases/download/v1.7.3rc1/robotframework_ride-1.7.3rc1- py2.py3-none-any.whl (bug多呀)
sudo -H pip install -U https://github.com/HelioGuilherme66/RIDE/archive/release.zip 修復了可以查看關鍵字幫助的bug 暫時用這個看看
V1.7.3)
f. 安裝常用的庫
pip install requests
pip install robotframework-requests
pip install robotframework-selenium2library
pip install robotframework-seleniumlibrary
pip install selenium
pip install robotframework-appiumlibrary
g. 在 MAC電腦的terminer終端運行 ride.py,如下圖 ride 運行成功:
整個環境配置踩得的坑不要不要的,希望以上的環境搭建介紹有效的減少大家踩坑的概率,現在可以愉快的開始自動化測試路程了,哈哈。
The End !