盆友們,沒有想到吧。干貨立馬就來(lái)了。
iOS自動(dòng)化測(cè)試環(huán)境搭建真是實(shí)力勸退??犹嗔恕?/p>
iOS平臺(tái)封閉、行業(yè)交流少、教程視頻也少。
這篇文章把自己搭建環(huán)境的步驟和遇到的坑都分享出來(lái)給有需要的盆友們。
一、前置基礎(chǔ)知識(shí)
開發(fā)者中心
官網(wǎng)地址:https://developer.apple.com/
- 提供開發(fā)文檔和開發(fā)工具,提升iOS平臺(tái)知識(shí)
- Team ID:登錄開發(fā)者賬號(hào),后臺(tái)獲得Team ID,個(gè)人開發(fā)者$99可以申請(qǐng)。
- bundle ID:也可以叫APP ID,它是每一個(gè)ios應(yīng)用的全球唯一標(biāo)識(shí),需要到member center->identifier->APP IDS去創(chuàng)建一個(gè)bundle id。
- 開發(fā)證書和發(fā)布證書:開發(fā)者使用開發(fā)證書,對(duì)外分發(fā)到app store或者使用ad-hoc模式分發(fā)使用發(fā)布證書。
Xcode
app store下載Xcode
-
模擬器:perference - componets 各種模擬器,需下載。 image
-
build image
-
創(chuàng)建模擬器 image
二、環(huán)境搭建
安裝appium
- 安裝node
brew install node
- 安裝appium
npm install -g appium
- 檢查appium是否安裝成功
appium &
替換brew源
官網(wǎng):https://brew.sh/
brew在mac上是很好用的工具,建議安裝。安裝很簡(jiǎn)單,執(zhí)行以下命令。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
已經(jīng)安裝了brew的直接執(zhí)行下面命令,對(duì)brew源進(jìn)行替換:
# 替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替換Homebrew Bottles源
# 對(duì)于bash用戶
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
#對(duì)于zsh用戶
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
其他一些工具包的安裝
-
安裝libimobiledevice:一個(gè)跨平臺(tái)的軟件協(xié)議庫(kù)和工具來(lái)與iOS設(shè)備進(jìn)行本地通信。
brew install libimobiledevice -
安裝ios-deploy:一個(gè)使用命令行安裝ios app到連接的設(shè)備的工具。(設(shè)備ios9.3以上需安裝ios-deploy)
npm install -g ios-deploy或者brew install ios-deploy -
安裝ideviceinstaller:
brew install --HEAD ideviceinstaller安裝完成以上東西后,會(huì)生成idevice工具:
idevice_id -l 顯示連接設(shè)備udid -
安裝appium-doctor:appium-doctor是一個(gè)用于驗(yàn)證appium安裝環(huán)境的工具,可以診斷出Node/iOS/Android環(huán)境配置方面的常見問(wèn)題。
npm install appium-doctor -g安裝appium-doctorappium-doctor --ios指定--ios時(shí)只針對(duì)iOS環(huán)境配置進(jìn)行檢測(cè) -
安裝xcode命令行工具
xcode-select --install -
安裝gcc
brew install gcc -
安裝或者升級(jí)usbmuxd
# 升級(jí)usbmuxd
WebDriverAgent安裝
WebDriverAgent是由Facebook開發(fā)的一套開源框架,用于端對(duì)端的UI測(cè)試,能同時(shí)支持模擬器和真機(jī)。
github地址:https://github.com/facebookarchive/WebDriverAgent
我們?cè)诎惭bappium時(shí),/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent這個(gè)目錄下是已經(jīng)安裝了WebDriverAgent的,可以直接使用。
-
進(jìn)入webdriveragent目錄下,執(zhí)行命令:
./Scripts/bootstrap.sh。使用
bash -x ./Scripts/bootstrap.sh可以看到執(zhí)行命令的細(xì)節(jié),一定要記得執(zhí)行這條,否則編譯WebDriverAgent會(huì)報(bào)錯(cuò)。 連接上你的設(shè)備
-
使用xcode編譯webdriveragent
3.1 在/appium-webdriveragent下
3.2 WebDriverAgentLibopen WebDriverAgent.xcodeprojXcode會(huì)自動(dòng)打開新的項(xiàng)目3.3 WebDriverAgentRunnerimageimage3.4 xcode菜單欄->Product->Destination->你的設(shè)備
3.5 xcode菜單欄->Scheme->WebDriverAgentRunner
3.6 xcode菜單欄->Product->Test
3.8 控制臺(tái)輸出如下類似信息以及設(shè)備上成功安裝上webdriveragent視為成功imageimage
安裝app-inspector
app-inspector是一款UI元素查看器,以樹形視圖查看UI,并自動(dòng)生成XPath,官網(wǎng)地址:https://macacajs.github.io/app-inspector/
-
安裝macaca-cli
npm install macaca-cli -g檢查是否安裝成功:
macaca doctor -
安裝app-inspector
npm install app-inspector -g -
編譯XCTestWD
3.1 打開XCTestWD.xcodeproj
- ounter(line
3.2 XCTestWDopen /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj3.3 XCTestWDUITestsimageimage3.4 xcode菜單欄->Product->Test 3.5 安裝XCTestWD在你的設(shè)備上視為成功
連接你的設(shè)備
-
啟動(dòng)app-inspector
app-inspector -u 你的設(shè)備的udid --verbose如何獲得udid?命令
idevice_id -l啟動(dòng)成功會(huì)自動(dòng)打開一個(gè)瀏覽器頁(yè)。
image