Mac Appium详细安装教程

Mac Appium详细安装教程

1. 直接安装:

Appium官网下载:https://bitbucket.org/appium/appium.app/downloads/

这里mac系统升级到 Sierra后,无法安装不被认可的软件,必须恢复“任何来源”,运行命令 sudo spctl –master-disable,成功后如图所示:

Z0B2vV.png

注意⚠️:
如果允许appium-doctor遇到问题,由于Appium无法探测到Mac OS 10.11以上的版本,解决办法如下所示:

1
grep -rl "Could not detect Mac OS X Version from sw_vers output:" /Applications/Appium.app/

终端输出如下信息

Terminal will show : /Applications/Appium.app//Contents/Resources/node_modules/appium/node_modules/appium-support/build/lib/system.js /Applications/Appium.app//Contents/Resources/node_modules/appium/node_modules/appium-support/lib/system.js /Applications/Appium.app//Contents/Resources/node_modules/appium-support/build/lib/system.js /Applications/Appium.app//Contents/Resources/node_modules/appium-support/lib/system.js

通过vim按照如下所示对每个文件进行编辑

vim /Applications/Appium.app//Contents/Resources/node_modules/appium/node_modules/appium-support/build/lib/system.js

1
2
3
4
5
6
7
8
9
10
11
Change From ->

case 10:
_arr = ['10.8', '10.9', '10.10', '10.11'];
_i = 0;

To ->

case 10:
_arr = ['10.8', '10.9', '10.10', '10.11','10.12', '10.13', '10.14'];
_i = 0;

vim /Applications/Appium.app//Contents/Resources/node_modules/appium/node_modules/appium-support/lib/system.js

1
2
3
4
5
6
7
8
9
10
11
Change From ->

try {
stdout = (await exec('sw_vers', ['-productVersion'])).stdout;
}

To ->

try {
stdout = (await exec('sw_vers', ['-productVersion'])).stdout.trim();
}
1
2
3
4
5
6
7
8
9
10
11
Change From ->

for (let v of ['10.8', '10.9', '10.10', '10.11']) {
if (stdout.indexOf(v) === 0) { return v; }
}

To ->

for (let v of ['10.8', '10.9', '10.10', '10.11','10.12', '10.13', '10.14']) {
if (stdout.indexOf(v) === 0) { return v; }
}

vim /Applications/Appium.app//Contents/Resources/node_modules/appium-support/build/lib/system.js

1
2
3
4
5
6
7
8
9
10
Change From ->

case 10:
_arr = ['10.8', '10.9', '10.10', '10.11'];
_i = 0;

To ->

case 10:
_arr = ['10.8', '10.9', '10.10', '10.11', '10.12', '10.13', '10.14'];

vim /Applications/Appium.app//Contents/Resources/node_modules/appium-support/lib/system.js

1
2
3
4
5
6
7
8
9
10
11
Change From ->

try {
stdout = (await exec('sw_vers', ['-productVersion'])).stdout;
}

To ->

try {
stdout = (await exec('sw_vers', ['-productVersion'])).stdout.trim();
}
1
2
3
4
5
6
7
8
9
10
11
Change From ->

for (let v of ['10.8', '10.9', '10.10', '10.11']) {
if (stdout.indexOf(v) === 0) { return v; }
}

To ->

for (let v of ['10.8', '10.9', '10.10', '10.11','10.12', '10.13', '10.14']) {
if (stdout.indexOf(v) === 0) { return v; }
}

2. 命令行安装

brew install node # get node.js 或者直接安装:Node.js官网下载:https://nodejs.org/zh-cn/download/(直接安装的node中直接包含了npm,且路径正确,不存在关联错误的情况)

npm install -g appium # get appium

npm install wd # get appium client

直接用npm下载往往不成功,这是需要通过代理来下载,我参考的文章是:https://segmentfault.com/q/1010000006025361/a-1020000006252474

具体方法如下:

1
2
3
4
5
6
7
> npm i cnpm -g --registry=http://registry.npm.taobao.org

> cnpm i appium -g # get appium

> cnpm i wd -g  # get appium client

> cnpm i appium-doctor   # get appium-doctor

3.检查Appium成功安装

appium-doctor

以上有部分软件未安装,接下来弥补上。

Appium配置

  1. AppStore下载Xcode直接安装即可;

或者命令行安装: $ xcode-select --install

  1. Android SDK 下载地址:http://tools.android-studio.org/index.php/sdk

    将下载的 Android SDK 解压,将得到如下目录。(具体安装步骤可以阅读 SDK Readme.txt)

 点击运行文件tools/android, 安装步骤一步一步安装并下载完SDK后,配置环境变量

1
2
3
4
5
6
> vim ~/.bash_profile  
export ANDROID_HOME=/usr/local/android-sdk-macosx

export PATH=${PATH}:${ANDROID_HOME}/tools

export PATH=${PATH}:${ANDROID_HOME}/platform-tools

  1. 网上下载java安装后,配置环境变量 (详细参照:http://www.micmiu.com/lang/java/set-javahome-on-mac-os-x/)

    1
    2
    3
    4
    5
    6
    > vim ~/.bash_profile   
    export JAVA_HOME=$(/usr/libexec/java_home) # get latest version

    export PATH=${JAVA_HOME}/bin:$PATH

    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  2. 检查Appium成功安装

Z0Bc3q.png

所有配置全部打对勾才算成功,若有打叉的,依次配置,直到全部对勾为止

坚持原创技术分享,打赏一杯咖啡钱呗。Donate click here.