Mac 下 appium +python 自動(dòng)化測(cè)試系列:
Mac 下搭建 appium+ios+python 自動(dòng)化測(cè)試環(huán)境(一)
Mac 下 appium 自動(dòng)化測(cè)試iOS 測(cè)試配置和腳本編寫(xiě)(二)
Mac 下 搭建appium +android+python 自動(dòng)化測(cè)試環(huán)境(三)
Mac 下 appium 自動(dòng)化測(cè)試 Android 測(cè)試配置和腳本編寫(xiě)(四)
環(huán)境搭建要求,MAC 機(jī)器一臺(tái),要求 Xcode 8.0以上,有 Apple ID 賬號(hào),懂一點(diǎn)點(diǎn)終端命令,最重要的是能夠聯(lián)網(wǎng),如果都 OK 了,那就可以開(kāi)搞了!
- 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)以下錯(cuò)誤
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)安裝,但是沒(méi)有 link 到 brew,還有就是文件夾權(quán)限問(wè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 文件安裝安裝完會(huì)顯示如下信息:
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(主要是因?yàn)閴途W(wǎng)絡(luò)的問(wèn)題,換成淘寶的 cnpm)
npm install -g cnpm --registry=https://registry.npm.taobao.org
安裝這個(gè)坑比較多,一般會(huì)出現(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.
這個(gè)時(shí)候你換成
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
如果臉不好,或者網(wǎng)絡(luò)問(wèn)題,又會(huì)出現(xiàn)以下問(wè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)上找一了一圈,還是沒(méi)解決,最后還是根據(jù)權(quán)限提示,自己摸索出來(lái)的,先打開(kāi)目錄權(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
這個(gè)會(huì)出現(xiàn)超時(shí)錯(cuò)誤
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
感覺(jué)就是淘寶的鏡像源的問(wèn)題,沒(méi)有同步或者什么原因,解決方法如下:
//設(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
如果沒(méi)使用代理或者公司網(wǎng)有限制的話,一般沒(méi)問(wèn)題。
- 9.安裝 appium1.8 release版本可以終端安裝也可以下載桌面端appium 桌面端下載鏈接 選擇 dmg 或者 desktop 版本。因?yàn)槲覀兦懊媾渲眠^(guò) npm 的鏡像源了,所以直接:
npm install -g appium
安裝完順便安裝 appium doctor
npm install -g appium-doctor
公司網(wǎng)絡(luò)太坑,我用的手機(jī)熱點(diǎn)下的,媽蛋啊,心疼我的流量!
接著安裝 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)安裝,請(qǐng)先卸載
#npm uninstall appium-xcuitest-driver
npm install appium-xcuitest-driver
- 13.配置 WebDriverAgent
首先,我想說(shuō)這個(gè) appium 自帶的項(xiàng)目,有毒啊!!這個(gè)真的有毒啊,絕對(duì)有毒啊!
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
sh ./Scripts/bootstrap.sh
運(yùn)行完,就是報(bào)fatal: could not read Username for 'https://github.com': terminal prompts disabled
這個(gè)錯(cuò)誤啊,原因竟然是,依賴庫(kù)里面的 Cartfile里面的依賴庫(kù)不見(jiàn)了啊!我搞了一天多,搜索都搜索的要吐了!
正確姿勢(shì)如下,請(qǐng) 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)然如果沒(méi)有安裝自帶的就不用執(zhí)行這個(gè)指令)
ln -s ~/WebDriverAgent WebDriverAgent (其中~/WebDriverAgent是源地址,后面的是目標(biāo)地址,也就是把你 clone 的項(xiàng)目鏈接到 driver 里面)
- 14.編譯 WebDriverAgent
1.進(jìn)入目標(biāo)文件或者你剛鏈接的源文件也行(鏈接之后源文件改變,引用文件也會(huì)改變)
-
雙擊WebDriverAgent.xcodeproj打開(kāi)此項(xiàng)目,這個(gè)項(xiàng)目由facebook開(kāi)源.在這里我們的目的就是更改一些配置,讓他能夠編譯成功,首先編譯之前你得有 ID賬號(hào),并且登錄你的Xcode賬戶
配置開(kāi)發(fā)證書(shū)等
接著編譯WebDriverAgentRunner
配置 runner 的證書(shū)信息
配置 setting 信息
- 15.建立服務(wù)WebDriverAgent (手機(jī)和MAC都在同一個(gè)網(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 **
這個(gè)是時(shí)候iphone多了一個(gè)WebDriverAgentRunner的app
我們?cè)谕ㄓ迷O(shè)置的描述文件里面信任我們的開(kāi)發(fā)證書(shū)
之后再次運(yùn)行上面的指令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真機(jī)的udid' test
如果出現(xiàn)以下信息,表示運(yù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
這個(gè)時(shí)候我們來(lái)一遍驗(yàn)證吧。
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
至此,說(shuō)明我們環(huán)境配置成功了!
整個(gè)環(huán)境配置踩得的坑不要不要的,主要是公司是內(nèi)網(wǎng),上外網(wǎng)用的代理,也沒(méi)法掛 VPN,希望以上的環(huán)境搭建真實(shí)有效的減少你們踩坑的幾率,愉快的開(kāi)始自動(dòng)化測(cè)試路程!下一篇,我會(huì)寫(xiě)一下如何進(jìn)行腳本測(cè)試和 appium desktop 的使用!
參考: