Appium的搭建有兩種方式:
1、使用Appium gui,直接下載appium.dmg
2、使用Terminal命令行安裝(強(qiáng)烈推薦)
一、使用Appium gui
1、下載Appium客戶端
https://bitbucket.org/appium/appium.app/downloads/
(這里需要自備梯子,極其難以下載)
2、安裝完后運(yùn)行appium-doctor檢查配置項(xiàng)

然后會(huì)看到一大堆的報(bào)錯(cuò),一一來解決就行。主要是JAVA_HOME、ANDROID_HOME、APPIUM_HOME、Xcode Command Line Tools、Carthage等等。
// JAVA Home
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_45, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
找到JAVA_HOME后,我們把它配置到.bash_profile中去。其他的如ANDROID_HOME之類的也類似,都配置到bash_profile中就可以了。最后Xcode Command Line 是可以自動(dòng)修復(fù)的,其余的收工處理。
// 創(chuàng)建.bash_profile文件
$ touch .bash_profile
// 輸入 open -e .bash_profile
$ open -e .bash_profile
全部修復(fù)完畢,會(huì)看到提示Everything looks good, bye!

二、使用Terminal命令行安裝
前言,我們知道Appium也是依賴node環(huán)境的,我們這里最好是也用brew來配置node環(huán)境。安裝完成后,檢查輸入$ node -v檢查是否安裝正確

1、使用npm命令安裝Appium
這里需要注意的是先得授權(quán),避免權(quán)限問題。然后是掛個(gè)代理科學(xué)上網(wǎng),這是開發(fā)人員必備技能啊。
$sudo chmod -R 777 /usr/local
$ npm install -g appium
官網(wǎng)介紹:http://appium.io/getting-started.html?lang=zh
2、使用npm命令安裝appium-doctor
$ npm install -g appium-doctor
3、使用appium-doctor檢查appium環(huán)境

跟上面安裝客戶端一樣,那里報(bào)錯(cuò)就改哪里。沒有配置環(huán)境的,配置環(huán)境。沒有安裝的比如Carthage就上官網(wǎng)下個(gè)包安裝下,直到最后一切ok為止。
Carthage鏈接:https://github.com/Carthage/Carthage#installing-carthage
4、都沒問題后,運(yùn)行一下試試吧。

三、其他可能出現(xiàn)的問題
1、早期的版本還遇到了和max OX 10.12更高系統(tǒng)不兼容的地方
解決方案也很簡(jiǎn)單,參見stackoverflow:http://stackoverflow.com/questions/40129794/how-to-fix-error-could-not-detect-mac-os-x-version-from-sw-vers-output-10-12/40168992#40168992
主要就是相關(guān)代碼位置添加具體的版本控制:
grep -rl "Could not detect Mac OS X Version from sw_vers output:" /Applications/Appium.app/
1. 在版本控制中添加’10.12’
2. 添加.trim()方法
try {
stdout = (await exec('sw_vers', ['-productVersion'])).stdout.trim();
}
2、Error: targetSdkVersionFromManifest failed. Original error: Cannot read property '1' of null
這個(gè)問題已經(jīng)在2.9.1 fix,(權(quán)限問題API>23)
https://github.com/appium/appium/issues/7353
需要更新appium-adb,這里一定要在node目錄下執(zhí)行,要不然會(huì)提示失?。。。?/p>
$ npm install appium-adb@2.9.1
3、修改源代碼避免每次運(yùn)行都安裝setting\unlock\ime等apk,這里以1.6.3版本為例子
文件: /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/driver.js,注釋以下幾句代碼
await this.adb.uninstallApk(this.opts.appPackage);
await helpers.installApkRemotely(this.adb, this.opts);
await helpers.resetApp(this.adb, this.opts.app, this.opts.appPackage, this.opts.fastReset);
await this.checkPackagePresent();
文件:/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/build/lib/driver.js 注釋以下幾句代碼
return _regeneratorRuntime.awrap(_androidHelpers2['default'].resetApp(this.adb, this.opts.app, this.opts.appPackage, this.opts.fastReset));
return _regeneratorRuntime.awrap(this.adb.uninstallApk(this.opts.appPackage));
return _regeneratorRuntime.awrap(_androidHelpers2['default'].installApkRemotely(this.adb, this.opts));
return _regeneratorRuntime.awrap(this.checkPackagePresent());
文件:/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/android-helpers.js 注釋以下幾句代碼
await adb.install(unicodeIMEPath, false);
await helpers.pushSettingsApp(adb);
await helpers.pushUnlock(adb);
文件 /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/build/lib/android-helpers.js 替換以下幾句代碼
return _regeneratorRuntime.awrap(helpers.initUnicodeKeyboard(adb)) 替換為return context$1$0.abrupt('return', defaultIME);
return _regeneratorRuntime.awrap(helpers.pushSettingsApp(adb)); 替換為return context$1$0.abrupt('return', defaultIME);
return _regeneratorRuntime.awrap(helpers.pushUnlock(adb)); 替換為return context$1$0.abrupt('return', defaultIME);
4、更新appium到最新版
$ npm install -g appium