Mac 下 appium +python 自動化測試系列:
Mac 下搭建 appium+ios+python 自動化測試環(huán)境(一)
Mac 下 appium 自動化測試iOS 測試配置和腳本編寫(二)
Mac 下 搭建appium +android+python 自動化測試環(huán)境(三)
Mac 下 appium 自動化測試 Android 測試配置和腳本編寫(四)
環(huán)境搭建要求想括,MAC 機(jī)器一臺龙巨,要求 Xcode 8.0以上劝术,有 Apple ID 賬號,懂一點點終端命令风钻,最重要的是能夠聯(lián)網(wǎng),如果都 OK 了,那就可以開搞了捞魁!
- 1.安裝 Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 2.安裝 libimobiledevice
brew install libimobiledevice
- 3.安裝 ideviceinstaller(真機(jī)安裝相關(guān))
brew install ideviceinstaller
- 4.安裝 carthage
brew install carthage
安裝 carthage
容易出現(xiàn)以下錯誤
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
原因是carthage
已經(jīng)安裝在张,但是沒有 link 到 brew用含,還有就是文件夾權(quán)限問題,在終端輸入:
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
brew link carthage
-
5.安裝
node
(目的是安裝 npm)官方下載地址https://nodejs.org/en/download/,下載.pkg 文件安裝安裝完會顯示如下信息:
This package has installed:
? Node.js v8.11.2 to /usr/local/bin/node
? npm v5.6.0 to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
- 6.安裝 cnpm(主要是因為墻和網(wǎng)絡(luò)的問題帮匾,換成淘寶的 cnpm)
npm install -g cnpm --registry=https://registry.npm.taobao.org
安裝這個坑比較多啄骇,一般會出現(xiàn)以下提示:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
這個時候你換成
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
如果臉不好,或者網(wǎng)絡(luò)問題瘟斜,又會出現(xiàn)以下問題:
npm WARN registry Unexpected warning for https://registry.npm.taobao.org/: Miscellaneous Warning ETIMEDOUT: request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 114.55.80.225:443
npm WARN registry Using stale package data from https://registry.npm.taobao.org/ due to a request error during revalidation.
網(wǎng)上找一了一圈缸夹,還是沒解決痪寻,最后還是根據(jù)權(quán)限提示,自己摸索出來的虽惭,先打開目錄權(quán)限橡类,然后再安裝鏡像
sudo chown $(whoami):admin /usr/local/lib/node_modules/
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 7.安裝 iOS-deploy
cnpm install -g ios-deploy
這個會出現(xiàn)超時錯誤
Get /binary-mirror-config/latest from https://registry.npm.taobao.org error: ConnectionTimeoutError: Connect timeout for 5000ms, GET https://registry.npmjs.org/binary-mirror-config/latest -2
感覺就是淘寶的鏡像源的問題,沒有同步或者什么原因芽唇,解決方法如下:
//設(shè)置鏡像源
npm config set registry https://registry.npm.taobao.org --global
//配置鏡像列表
npm config list
//執(zhí)行安裝指令
npm install -g ios-deploy
- 8.安裝 xcpretty
gem install xcpretty
如果沒使用代理或者公司網(wǎng)有限制的話顾画,一般沒問題。
- 9.安裝 appium1.8 release版本可以終端安裝也可以下載桌面端appium 桌面端下載鏈接 選擇 dmg 或者 desktop 版本匆笤。因為我們前面配置過 npm 的鏡像源了研侣,所以直接:
npm install -g appium
安裝完順便安裝 appium doctor
npm install -g appium-doctor
公司網(wǎng)絡(luò)太坑,我用的手機(jī)熱點下的炮捧,媽蛋啊庶诡,心疼我的流量!
接著安裝 python 的環(huán)境
git clone git@github.com:appium/python-client.git
cd python-client
python setup.py install
- 10.安裝 wd
npm install -g wd
- 11.安裝 webpack
npm i -g webpack
- 12.安裝 appium-xcuitest-driver依賴
#如果已經(jīng)安裝寓盗,請先卸載
#npm uninstall appium-xcuitest-driver
npm install appium-xcuitest-driver
- 13.配置 WebDriverAgent
首先灌砖,我想說這個 appium 自帶的項目,有毒翱觥;浴!這個真的有毒啊善炫,絕對有毒傲糜摹!
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
sh ./Scripts/bootstrap.sh
運行完箩艺,就是報fatal: could not read Username for 'https://github.com': terminal prompts disabled
這個錯誤啊窜醉,原因竟然是,依賴庫里面的 Cartfile里面的依賴庫不見了耙兆弧榨惰!我搞了一天多,搜索都搜索的要吐了静汤!
正確姿勢如下琅催,請 get??
先進(jìn)到用戶目錄下或者根目錄下:
cd ~
git clone https://github.com/facebook/WebDriverAgent.git
cd WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
sh ./Scripts/bootstrap.sh
一頓操作猛如虎之后, 進(jìn)入到appium-xcuitest-driver路徑下
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/
rm –rf WebDriverAgent(移除自帶的虫给,當(dāng)然如果沒有安裝自帶的就不用執(zhí)行這個指令)
ln -s ~/WebDriverAgent WebDriverAgent (其中~/WebDriverAgent是源地址藤抡,后面的是目標(biāo)地址,也就是把你 clone 的項目鏈接到 driver 里面)
- 14.編譯 WebDriverAgent
1.進(jìn)入目標(biāo)文件或者你剛鏈接的源文件也行(鏈接之后源文件改變抹估,引用文件也會改變)
-
雙擊WebDriverAgent.xcodeproj打開此項目缠黍,這個項目由facebook開源.在這里我們的目的就是更改一些配置,讓他能夠編譯成功药蜻,首先編譯之前你得有 ID賬號瓷式,并且登錄你的Xcode賬戶
接著編譯WebDriverAgentRunner
- 15.建立服務(wù)WebDriverAgent (手機(jī)和MAC都在同一個網(wǎng)段下替饿,且都能連接外網(wǎng))關(guān)閉Xcode,進(jìn)入WebDriverAgent 文件夾
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真機(jī)的udid' test
如果終端出現(xiàn)以下信息蒿往,表示編譯 OK
Testing failed:
Early unexpected exit, operation never finished bootstrapping - no restart will be attempted
** TEST FAILED **
這個是時候iphone多了一個WebDriverAgentRunner的app
我們在通用設(shè)置的描述文件里面信任我們的開發(fā)證書
之后再次運行上面的指令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真機(jī)的udid' test
如果出現(xiàn)以下信息盛垦,表示運行成功了:
2018-04-26 16:25:33.445429+0800 WebDriverAgentRunner-Runner[314:21633] Continuing to run tests in the background with task ID 1
Test Suite 'All tests' started at 2018-04-26 16:25:33.508
Test Suite 'WebDriverAgentRunner.xctest' started at 2018-04-26 16:25:33.509
Test Suite 'UITestingUITests' started at 2018-04-26 16:25:33.510
Test Case '-[UITestingUITests testRunner]' started.
t = 0.01s Start Test at 2018-04-26 16:25:33.518
t = 0.01s Set Up
2018-04-26 16:25:33.527655+0800 WebDriverAgentRunner-Runner[314:21633] Built at May 22 2018 07:53:09
2018-04-26 16:25:33.552834+0800 WebDriverAgentRunner-Runner[314:21633] ServerURLHere->http://172.20.10.7:8100<-ServerURLHere
這個時候我們來一遍驗證吧。
appium-doctor --ios
出現(xiàn)如下信息:
info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ? The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ? Node version is 8.11.2
info AppiumDoctor ? Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ? Xcode Command Line Tools are installed.
info AppiumDoctor ? DevToolsSecurity is enabled.
info AppiumDoctor ? The Authorization DB is set up properly.
info AppiumDoctor ? Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor ? HOME is set to: /Users/xxxxxx
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor
至此瓤漏,說明我們環(huán)境配置成功了腾夯!
整個環(huán)境配置踩得的坑不要不要的,主要是公司是內(nèi)網(wǎng)蔬充,上外網(wǎng)用的代理蝶俱,也沒法掛 VPN,希望以上的環(huán)境搭建真實有效的減少你們踩坑的幾率饥漫,愉快的開始自動化測試路程榨呆!下一篇,我會寫一下如何進(jìn)行腳本測試和 appium desktop 的使用庸队!
參考: