Appium Appium for Mac 环境准备篇

国文 · August 05, 2014 · Last by rwzhen replied at November 19, 2018 · 3609 hits
本帖已被设为精华帖!

之前写过一篇Appium for windows的文章,因为是 09 年的 T400,启动 Android 模拟器的时候死机三次,那就公司申请台 Macbook air 吧,15 寸的 Macbook Pro 实在太重了,也就 Mac 才能真正发挥 Appium 的功能,支持 Android 和 iOS。好了,废话不多,开始。

1. 爬墙
因为后续安装过程中可能会碰到墙的问题,所以首先得解决爬墙的问题。
我的方便,公司提供代理。

2. java
guowenxie-macbookair:~ guowenxie$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

3. git
guowenxie-macbookair:~ guowenxie$ git --version
git version 1.8.5.2 (Apple Git-48)

4. ruby
guowenxie-macbookair:~ guowenxie$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]

5. brew
guowenxie-macbookair:~ guowenxie$ brew -v
Homebrew 0.9.5

这边提下 brew 的安装,brew是 Mac OS 不可或缺的套件管理器
执行下面命令
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

6. node
有了 brew 安装 node 就方便了
brew install node

7. npm
guowenxie-macbookair:~ guowenxie$ npm -v
2.0.0-alpha-5

8. Appium
现在可以开始安装 Appium

guowenxie-macbookair:~ guowenxie$ appium -v
1.2.0

9. wd
npm install wd

10. Xcode 和 Android SDK
这个不说了

11. 检查环境
Appium 提供了一个 doctor,运行 appium-doctor
guowenxie-macbookair:~ guowenxie$ appium-doctor
Running iOS Checks
✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer
✖ Xcode Command Line Tools are NOT installed: Error: Command failed: No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
Fix it? (y/n) y
Press any key to continue:
✔ Xcode Command Line Tools are installed.
✔ DevToolsSecurity is enabled.
✔ The Authorization DB is set up properly.
✔ Node binary found at /usr/local/bin/node
✔ iOS Checks were successful.
Running Android Checks
✖ ANDROID_HOME is set but does not exist on the file system at "Users/guowenxie/Documents/adt-bundle_mac-x86_64-20140702/sdk"
Appium-Doctor detected problems. Please fix and rerun Appium-Doctor.

这里可以看到我 Xcode Command Line Tools 没有安装,这个方便,Fix it?的时候输入 Y,就能自动导向安装了。
另一个是 ANDROID_HOME 的环境变量没配置好,那么我们要配置下。

12. bash_profile 文件
Mac 默认是没有这个文件的,我们自己建一个
touch .bash_profile

vi .bash_profile
打开 bash_profile 文件配置 ANDROID_HOME 和 JAVA_HOME
export ANDROID_HOME="/Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk"
export JAVA_HOME=$(/usr/libexec/java_home)

source .bash_profile
好了,再次运行 appium-doctor
guowenxie-macbookair:~ guowenxie$ appium-doctor
Running iOS Checks
✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer
✔ Xcode Command Line Tools are installed.
✔ DevToolsSecurity is enabled.
✔ The Authorization DB is set up properly.
✔ Node binary found at /usr/local/bin/node
✔ iOS Checks were successful.
Running Android Checks
✔ ANDROID_HOME is set to "/Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk"
✔ JAVA_HOME is set to "/usr/libexec/java_home."
✔ ADB exists at /Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb
✔ Android exists at /Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/android
✔ Emulator exists at /Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/emulator
✔ Android Checks were successful.
✔ All Checks were successful

到此,环境基本准备好了。

最后,如果不想通过命令行安装 Appium,也可以安装 dmg

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 53 条回复 时间 点赞

纠结了 2 天才肯到这帖子,哎苦闷。说的坑比描述的多

国文 #2 · August 05, 2014 Author

@caovcao ,请加上头像,阅读下论坛须知

留个记号,学习!!

麻烦问一下,appium 测试结束后自动生成的测试报告,以及测试过程中发现问题的统计、log 的抓取这些是一个怎样的情况呢,有没有已经涉及到了?

国文 #5 · August 06, 2014 Author

@sas , 目前 appium 是没有提供测试报告的吧,你提到的这些应该算一套方案了,可以单独发帖来讨论

#4 楼 @sas appium 提供了 webhook,可以讲 appiu 的 log 全部导入到你自己的分析工具里去。

不错的帖子,挺全面的

遇到启动不了的问题了 ,尝试了重新安装和提升权限 还是无法解决,求解
LovetekiMac:/ love$ appium &
[1] 1270
LovetekiMac:/ love$ error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using sudo npm install -g appium, the solution is to reinstall Node using a method (Homebrew, for example) that doesn't require sudo to install global npm packages.

[1]+ Exit 1 appium

@ 8 楼,这个问题很常见,网上的资料也很多, 好像有个码农老毕的博客,你可以去看看,他有关于这个问题的解决方案。

@beerbox ,按着那个帖子做了 还是没解决 的

那就是你安装 nodejs 有问题,之前跟你差不多情况,弄了好久。

#8 楼 @caovcao 重装啊 不要用 sudo 啊 把之前 sudo 安装过的全部卸载了。

各位好,我之前在公司花了好半天劲终于装上了 Appium,想请问一下在没有源码的条件下,可以在图形化 Appium 上运行真机 iOS 的测试吗?

好文章,感谢花时间整理文档,分享给大家的人

16Floor has deleted

楼主,我现在卡在了 android home 的设置,请问是要新建 touch .bash_profile 和 vi .bash_profile 两个文件吗?

#18 楼 @neverever 是的,默认这个文件是没有的,你要自己创建,不要用 sudo 权限。

Homebrew 安装的最新 url: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

mark! 楼主,我在执行 npm install -g appium 的时候提示解压缩错误...

今天晚上,跟着你的帖子,结合恒温的这篇帖子 https://testerhome.com/topics/315 一起看,我终于把环境搭建起来了。其中遇到的问题就是安装 appium 的时间过程比较长,还有踩到 npm --install 安装中的一些坑。我把 npm 的 Registry 进行了重新的配置。
(以下方法从谷歌搜来的,我尝试了第一种和第二种方法)
1.通过 config 命令
npm config set registry https://registry.npm.taobao.org
npm info underscore(如果上面配置正确这个命令会有字符串 response)
2.命令行指定
npm --registry https://registry.npm.taobao.org info underscore
3.编辑 ~/.npmrc 加入下面内容
registry = https://registry.npm.taobao.org

上面的 Registry 链接可以自行谷歌搜索选择

我回去也试试

遇到问题了,搜索了好多都没解决,来此求助。我在 mac 终端上运行 npm install wd,总是提示如下错误:
/Users/zz
├── appium-android-driver@1.8.0
└── wd@0.4.0

npm WARN enoent ENOENT: no such file or directory, open '/Users/zz/package.json'
npm WARN zz No description
npm WARN zz No repository field.
npm WARN zz No README data
npm WARN zz No license field.

问题 1:弹出这个错误,不知道是不是 webdriver 是不是已经安装的原因还是其他啥
问题 2:运行 appium-doctor 的时候,总是提示 appium-doctor: command not found
问题 3:当在代码里面引用 webdriver(from appium import webdriver)的时候提示:unresolved import: webdriver

求大家帮我看看,困扰好几天了

#24 楼 @zxning 问题已经解决
第 1 个问题貌似不用太关注,后来问题解决后,输入 npm install wd 还是会出现那个问题
第 2 个问题:运行 appium-doctor 之后需要先运行 npm install appium-doctor -g
第 3 个问题:是因为在 eclipse 里面设置关联到 Python-client 的安装目录下导致的,手动添加了 Python-client 的目录后,问题就解决了

在 Mac 上 安装 其他都好了,然而检测的时候 appium-doctor 提示 adb、android 等变量没有找到

tangdeMac:~ testT$ adb devices
List of devices attached
4df1c02429675fb5    device

tangdeMac:~ testT$ appium-doctor
info AppiumDoctor ### Diagnostic starting ###
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  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ HOME is set to: /Users/testT
info AppiumDoctor  ✔ ANDROID_HOME is set to: /Users/testT/Desktop/android-sdk-macosx/samples
info AppiumDoctor  ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
WARN AppiumDoctor  ✖ adb could NOT be found at '/Users/testT/Desktop/android-sdk-macosx/samples/platform-tools/adb'!
WARN AppiumDoctor  ✖ android could NOT be found at '/Users/testT/Desktop/android-sdk-macosx/samples/tools/android'!
WARN AppiumDoctor  ✖ emulator could NOT be found at '/Users/testT/Desktop/android-sdk-macosx/samples/tools/emulator'!
info AppiumDoctor ### Diagnostic completed, 3 fixes needed. ###
info AppiumDoctor 
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor - Manually install adb and add it to PATH.
WARN AppiumDoctor - Manually install android and add it to PATH.
WARN AppiumDoctor - Manually install emulator and add it to PATH.
info AppiumDoctor ###
info AppiumDoctor 
info AppiumDoctor Bye, run appium-doctor again when the all the manual fixes have been applied!
info AppiumDoctor 
tangdeMac:~ testT$ 

实际上 adb 是已经配置到环境变量了的 并且可以正常使用,猜测是不是权限的原因?

OS 版本 10.11.4

我想问下 Xcode Command Line Tools are NOT installed! ,您说的 Fix it?然后选 y 这个操作在哪里呢?Xcode 上已经有命令行工具了啊,还需要在下载一个吗?

#25 楼 @zxning 搜到了您的答案,特地注册账号以表达感谢。😄

#25 楼 @zxning 我正在搭建 appium,遇到了跟你一样的第二个报错,因为你的答案解决了我的问题,特地留言感谢,谢谢你的:npm install appium-doctor -g

不知道还有没有人回帖,想请教一下各位,第 9 步:npm install wd,其中 wd 有什么作用?我执行到这里的时候总是通不过,如下图。请问哪位知道原因?多谢!

国文 #31 · April 20, 2017 Author
ZhaooRui 回复

wd 是 webdriver, 执行不过估计没 ***,你换个源吧

国文 回复

多谢你的回复,请问还有什么源可以换呀?😀

请问 appium 安装好后要设置环境变量的吗
我通过 appium.dmg 安装好后,在终端输入 appium -v,提示 command not found

命令行安装 appium 时,在进度条进行到
extract:appium-espresso-driver:sill extract bluebird@3.5.0
就卡主了,关掉终端后重新输入,还是卡在这里。node、brew、npm 都安装了啊

国文 回复

额……我看这个 issue 已经关闭了,是还没有更新?

国文 #37 · November 23, 2017 Author
shela2009 回复

和网速有关,倒数第二个回答

国文 回复

网速解释不了啊……前面都挺快的,一到那个点就卡住了

使用 cnpm 能安装了,但是每次会卡在 selenium jar 这个步骤:

info Selendroid Downloading Selendroid standalone server version 0.17.0 from http://repo1.maven.org/maven2/io/selendroid/selendroid-standalone/0.17.0/selendroid-standalone-0.17.0-with-dependencies.jar --> /usr/local/lib/node_modules/appium/node_modules/_appium-selendroid-driver@1.6.5@appium-selendroid-driver/selendroid/download/selendroid-server-7cf7163ac47f1c46eff95b62f78b58c1dabdec534acc6632da3784739f6e9d82.jar

我从这个地址可以把 jar 包下载下来,但是每次执行cnpm install -g appium时,download 文件夹会被删掉又重新创建,所以我也不能把下载后的 jar 包复制进去。
问了度娘后的方法,一般有两种:一种是等或者多尝试,多试几次不知道哪次就好了;还有一种是创建一个虚拟机,然后巴拉巴拉之类的就能把这个下载地址变成本地,然后引用本地下载的 jar 包。(https://testerhome.com/topics/7136 评论下的 xmlbw 的回答)
后面这种方法看得我云里雾里的。想问下有没有别的方法可以绕过这一步骤,或者别的方法能通过这个步骤的

国文 #40 · December 27, 2017 Author
shela2009 回复

npm install -g appium --registry=https://registry.npm.taobao.org

国文 回复

恩……这种做法跟用cnpm install -g appium是一样的吧?还是卡在 Selendroid jar 包这里

匿名 #42 · January 08, 2018

求问,我遇到这个,不知道怎么解决哇。有人遇到吗?
bogon:~ xxx$ appium-doctor
-bash: appium-doctor: command not found

匿名 #43 · January 08, 2018

额,糊涂了,原来我自己把 appium-doctor 对应的/usr/local/lib/node_modules/appium-doctor/appium-doctor.js 删掉了。。。
重新:npm install appium-doctor -g 执行完毕即可

匿名 #44 · January 13, 2018

又出现如下问题,一直没找到解决方法:
bogon:~ xxx$ appium -v
-bash: appium: command not found

执行 npm install -g appium ,报下面的错误,有么有大神帮忙看看

(node:2511) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/2018024-2511-shj17r.m1g9f'
(node:2511) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
info Chromedriver Install Installing Chromedriver version '2.33' for platform 'mac' and architecture '64'
info Chromedriver Install Opening temp file to write chromedriver_mac64 to...
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/2018024-2511-jwnl7p.relfq'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appium-chromedriver@3.1.4 install: node install-npm.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the appium-chromedriver@3.1.4 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

解决了,因为权限没有给

zxning 回复

大神,请问这个问题解决了吗,我也遇到了

有大神可以帮帮忙吗?为什么用 appium-doctor 检查环境的时候 所有都是配好的 但是用 appium desired capabilities 运行一个模拟器的时候 就一直报这个错

国文 #50 · August 09, 2018 Author
ruxia 回复

错误信息写得很清楚了吧,carthage 是不是没装,brew install carghage

@oscarxie 装了的 可以看第二张图 我用 appium-doctor 去 check 环境的时候 就有我 carthage 的安装路径 我也能用 carthage version 来查看版本 但是我不是很确定我的环境变量是不是配置正确的 我是配置在按照您这个教程第 12 步新建的 .bash_profile 文件里面的,像这样

52Floor has deleted
国文 #53 · August 09, 2018 Author
ruxia 回复

brew install carghage 执行了吗?

@oscarxie 你是说安装 carthage 的命令吗? brew install carthage 这个安装命令我执行过的,需要再执行一次吗?

shela2009 回复

我也是这个问题 请问你是怎么解决的呢?

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up