Appium Appium 开发环境搭建 (1)--配置源码运行环境

陈恒捷 · 2015年02月14日 · 最后由 随心录 回复于 2016年10月19日 · 184 次阅读
本帖已被设为精华帖!

这是一个系列文章,完整的合集链接:Appium 开发环境搭建合集

2015/2/25 update:
由于 testerhome/appium 已更新到最新版本,故把 更新代码库部分移到 Q&A 中。

2015/2/24 update:
把标题改为 Appium 开发环境搭建(1)-- 配置源码运行环境,同时微调了格式,以配合后续文章。

之前加入了 doctorq 的开源项目,今天提前配置一下 testerhome/appium 的源码运行环境。过程中发现有一些地方官方文档没有提到,在此分享一下配置过程。
PS:这是我的第一个贴子,有些地方写得不对或不够清晰请跟贴说明,我会立即更正。

1. 下载代码库

git clone https://github.com/testerhome/appium.git

然后运行此命令时所在的目录会出现一个appium文件夹。进入文件夹:

cd appium

3. 根据官方介绍配置从源码运行 appium 的环境(ios, android, seledroid)

参考资料:https://github.com/appium/appium/blob/master/docs/en/contributing-to-appium/appium-from-source.md
注意:我的配置环境为 Mac OS X 10.10.1。根据官方要求,配置过程中除非官方说明,否则尽量不要使用sudo命令。这里遇到的错误基本都和系统当前配置有关。可能有些人会遇到,有些人不会,请大家按照需要参考。

3.1 运行appium目录下的reset.sh 进行环境配置。

这个脚本进行了各个主要运行环境(ios, android, selendroid)的重置和更新,例如下载需要用到的 npm 包、安装 selendroid 等。
如果运行出错就加上--verbose参数再跑,看是哪里出错。

运行过程中我出现了几次错误,我把我遇到的错误信息和解决方案放在了文章末尾。大家可以参考一下(这里的信息都是用了--verbose后才会显示的).
另外,appium 官方有个地方也有说明其他常见错误及解决方案:https://github.com/appium/appium/blob/3f0aee727bd320377b63bbc57ab4b3fb591260c4/docs/en/appium-setup/troubleshooting.md
如果用上面的办法还是解决不了,可以去 github报个 issue来让 appium 团队帮忙寻找解决方案。

3.2(仅针对 ios)运行sudo ./bin/authorize-ios.js配置 ios 的认证环境(用来让 ios 不认为 appium 安装的应用有安全问题)。

$ sudo ./bin/authorize-ios.js
Password:
Enabling DevToolsSecurity
Updating security db for developer access
Granting access to built-in simulator apps
Authorization successful

3.3 使用node .运行 appium server:

$ node .
info: Welcome to Appium v1.3.5 (REV 80453f682c18c32377bdf5664533e4df69a62770)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug

至此,从源码运行 appium 的环境完成了。此时运行的 appium 就是从源码运行的了。如果是 debug 的话,这样基本足够了。但对于开发来说,但这只是配置开发环境的第一步(官方文档里的Setting up Appium from Source部分),后面还有Hacking on AppiumHacking with Appium for iOS, Hacking with Appium for Android来配置开发环境,以及Running TestsRunning individual tests来执行测试。后面我会根据官方文档(https://github.com/appium/appium/blob/master/docs/en/contributing-to-appium/appium-from-source.md)配置下去,如果有遇到官方文档内没有提到的问题,我会另外开贴来帮助大家处理这些问题。

Q&A

更新代码库

通过 Fork 出来的代码库都有可能存在和源代码库不一致的情况。在此简述一下如何更新代码库。
参考资料:https://help.github.com/articles/syncing-a-fork/

$ git fetch git fetch https://github.com/appium/appium.git
git fetch https://github.com/appium/appium.git
remote: Counting objects: 6600, done.
remote: Compressing objects: 100% (2708/2708), done.
remote: Total 6600 (delta 4470), reused 5589 (delta 3679)
Receiving objects: 100% (6600/6600), 15.70 MiB | 260.00 KiB/s, done.
Resolving deltas: 100% (4470/4470), done.
From https://github.com/appium/appium
 * branch            HEAD       -> FETCH_HEAD

$ git checkout master
Warning: you are leaving 1006 commits behind, not connected to
any of your branches:

  80453f6 getting rid of old ci code, use the old-travis-ci branch for reference
  6c8eade Merge pull request #4526 from appium/v1.3.5-branch
  a124a15 clarified garbled changelog text
  634d19b fixed changelog
 ... and 1002 more.

If you want to keep them by creating a new branch, this may be a good time
to do so with:

 git branch new_branch_name 80453f6

Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.


$ git merge FETCH_HEAD
Updating 99794ad..80453f6
Fast-forward
 .gitignore                                         |   21 +-
 .gitmodules                                        |   15 +
 .jscs.json => .jscsrc                              |    8 +-
 .jshintignore                                      |    5 +
 .jshintrc                                          |    2 +-
 .travis.yml                                        |   39 -
 CHANGELOG.txt                                      |  368 ++++-
 CONTRIBUTING.md                                    |  147 +-
 Gruntfile.js                                       |   69 +-
 README.md                                          |   86 +-
 ...
 create mode 100644 test/functional/selendroid/shutdown-specs.js
 create mode 100644 test/functional/selendroid/webview-auto-specs.js
 create mode 100644 test/helpers/sim-udid.js
 create mode 100755 test/tools/prepare-tap.js
 create mode 100644 test/unit/ios-device-specs.js
 create mode 100644 trigger.txt

查看代码库更新情况:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1006 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

注意:这里的同步仅仅更新了你的本地代码库,github 上的代码库还是旧的。需要使用git push命令才会把这个变更更新到远程代码库里。

运行./reset.sh过程出现的故障及解决方案

  • Error: EACCES, mkdir '/Users/hengjiechen/.npm/gulp-util/3.0.3' ``` $ ./reset.sh --verbose ./reset.sh --verbose ---- Resetting / Initializing Appium ---- RESETTING NPM * Installing new or updated NPM modules (including devDeps) npm ERR! Darwin 14.0.0 npm ERR! argv "node" "/usr/local/bin/npm" "install" "." npm ERR! node v0.10.36 npm ERR! npm v2.3.0 npm ERR! path /Users/hengjiechen/.npm/gulp-util/3.0.3 npm ERR! code EACCES npm ERR! errno 3

npm ERR! Error: EACCES, mkdir '/Users/hengjiechen/.npm/gulp-util/3.0.3'
npm ERR! { [Error: EACCES, mkdir '/Users/hengjiechen/.npm/gulp-util/3.0.3']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/hengjiechen/.npm/gulp-util/3.0.3',
npm ERR! parent: 'appium' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/hengjiechen/Develop/appiumSourceCode/appium/npm-debug.log
---- FAILURE: reset.sh exited with status 1 ----

**原因分析:**之前用管理员权限安装过npm,或者某些npm包用了管理员权限来安装。这里千万不要参照错误提示用管理员执行,否则appium就装不下去了。
**解决方案:**
卸载npm,删除`~/.npm`文件夹(部分目录没权限就用`sudo`来删),然后用`brew install npm`重新安装。安装后再运行`./reset.sh --verbose`(`brew`命令是`homebrew`的命令,提示没找到命令的请安装[homebrew]。不能用node官方安装程序来装)

*  Warning: Command failed: /bin/sh: mvn: command not found

...
RESETTING SELENDROID

  • Clearing out any old modified server apks
  • Cloning/updating selendroid Submodule 'submodules/selendroid' (https://github.com/selendroid/selendroid.git) registered for path 'submodules/selendroid' Cloning into 'submodules/selendroid'... remote: Counting objects: 16818, done. remote: Compressing objects: 100% (70/70), done. remote: Total 16818 (delta 20), reused 35 (delta 11) Receiving objects: 100% (16818/16818), 13.76 MiB | 304.00 KiB/s, done. Resolving deltas: 100% (7885/7885), done. Checking connectivity... done. Submodule path 'submodules/selendroid': checked out 'ec84567bb60cb2f47936aa4213be7ff537d2e596'
  • Building selendroid server and supporting libraries Running "buildSelendroidServer" task Building selendroid server Getting Selendroid version Selendroid version is 0.13.0 Unable to build selendroid server. Stdout was:

/bin/sh: mvn: command not found

Warning: Command failed: /bin/sh: mvn: command not found
Use --force to continue.

Aborted due to warnings.
---- FAILURE: reset.sh exited with status 1 ----

**原因分析**:没找到mvn命令。我没有装`maven`。
**解决方案**:参考下一个问题,使用以下命令安装`maven`

brew install homebrew/versions/maven31
sudo ln -s /usr/local/Cellar/maven31/3.1.1 /usr/local/Cellar/maven/
brew switch maven 3.1.1


*  Warning: Command failed: Exception in thread "pool-2-thread-1" java.lang.NoClassDefFoundError: org/eclipse/aether/spi/connector/Transfer$State

...
constituent[38]: file:/usr/local/Cellar/maven/3.2.5/libexec/lib/wagon-http-shared-2.8.jar
constituent[39]: file:/usr/local/Cellar/maven/3.2.5/libexec/lib/wagon-provider-api-2.8.jar

constituent[40]: file:/usr/local/Cellar/maven/3.2.5/libexec/conf/logging/

Exception in thread "pool-2-thread-1" java.lang.NoClassDefFoundError: org/eclipse/aether/spi/connector/Transfer$State
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:608)
at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
...
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 5 more
Use --force to continue.

Aborted due to warnings.
---- FAILURE: reset.sh exited with status 1 ----

**原因分析**:这是安装Selendroid时出错了,错误信息表示是找不到class的声明。这个只能求助google了。
**解决方案**:google后找到<https://github.com/appium/appium/issues/4490>,根据里面的解决方案使用下面命令修复:

brew install homebrew/versions/maven31
sudo ln -s /usr/local/Cellar/maven31/3.1.1 /usr/local/Cellar/maven/
brew switch maven 3.1.1


*  [ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources (default-generate-sources) on project android-driver-app

...
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources (default-generate-sources) on project android-driver-app: Execution default-generate-sources of goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources failed: Invalid SDK: Platform/API level 16 not available. This command should give you all you need:
[ERROR] /Applications/adt-bundle-mac-x86_64-20140702/sdk/tools/android update sdk --no-ui --obsolete --force
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :android-driver-app

Warning: Command failed: Use --force to continue.

Aborted due to warnings.
---- FAILURE: reset.sh exited with status 1 ----

**原因分析**:大致意思是没有找到Android sdk里的`Platform/API level 16`。官方文档提到配置seledroid的话需要用到level 16的API。
**解决方案**:装上level 16的API。
![](/photo/2015/5676739fe3196bfa8d18de749d7f5778.png)

*  Warning: Command failed: Feb 14, 2015 3:05:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryExecute

[INFO] Compiling 172 source files to /Users/hengjiechen/Develop/appiumSourceCode/appium/submodules/selendroid/selendroid-server/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:

The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
...
INFO: Retrying request
Feb 14, 2015 3:05:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request

Warning: Command failed: Feb 14, 2015 3:05:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Feb 14, 2015 3:05:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Feb 14, 2015 3:05:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Feb 14, 2015 3:05:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Use --force to continue.

Aborted due to warnings.
---- FAILURE: reset.sh exited with status 1 ----

**原因分析**:这个原因应该是编译器暂存空间不足导致的(StackOverflowError)。
**解决方案**:运行下面的命令加大暂存空间:

export MAVEN_OPTS="-Xms1024m -Xmx2048m -Xss2048k"




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

这些坑我都踩过,感谢总结啊! 真是好文章!提个建议,如果改了源码,需要加测试,那这个测试如何运行呢?

如果需要 build android chrome 的,chromedriver 如果没代理也下载不下来,需要调整下 reset.sh

@lihuazhang 现在还没做到这一步。我后面跑一下测试后再加上。看官方文档的话 unittest 只需要一个命令就可以跑了,不过里面有没有坑现在还不清楚……

@cosyman 所以我注明了 需要能连接国外网络。确实 chromedriver 没代理下不下来。你有调整过 reset.sh 来让它下载 chromedriver 的节点改为国内镜像吗?有的话麻烦在这里说一下,我更新到帖子内容里。谢谢。

#5 楼 @chenhengjie123 恩,第一遍看的不够细。我是直接把下载 chromedriver 那一段,人工做了。

testerhome 分支已更新到最新版本 [2015.02.25 晚 9 点 37]

@doctorq ok,我更新一下文章

reset.sh 执行成功的标志是什么?

@doctorq 执行成功的标志是最后一行是

---- reset.sh completed successfully ----

#10 楼 @chenhengjie123 看来我还没成功,一直卡在

Updated file E:\appium\lib\devices\android\bootstrap\build.xml
. . .

@doctorq 或者你查一下 grunt 里面的源码吧,看看那个 task 具体做了什么。
reset.sh 的 log 在用了--verbose后还是挺清晰的。
解决以后分享一下哈。我这个只记录了 mac 的,没有试过在 windows 下配置。

#12 楼 @chenhengjie123 我觉得应该是网络的原因。光标一直闪烁,不动,也不报错。等我装成功后,我把我遇到的问题加到你的帖子里

@doctorq 也有可能。现在我的电脑都开着 shadowsocks 了。

#14 楼 @chenhengjie123 公司电脑,限制太多,还是得回去弄

@emily 额,你这个不是搭建源码环境,而是搭建运行环境,所以我就不附到帖子里面了。

@chenhengjie123 准备学 appium for ios,请问个问题,搭建源码环境和搭建运行环境有什么区别。

@chenhengjie123 另外国内的 appium 资料太少了,大都是 for android ,请问在哪里可以学到 ios 的。目前已开通红杏帐号,可以浏览国外的网站

@chenhengjie123 最后麻烦问一下,怎么入门 appium。谢谢!

#21 楼 @tester_felix

  1. 源码环境和运行环境区别:源码环境需要从源码安装(废话),因此需要按照很多依赖库(seledroid,node.js 的依赖库等等),组建时间较长且需要修改某些系统设置,使用目的是进行 appium 的开发/源码学习。运行环境则主要是用 apppium 来测试手机应用,重点在使用 appium,希望安装依赖库这类问题越少越好(所以用 exe 或者.app 是最简单的,而且还能随时切换版本)。当然,源码环境也可以做运行环境。

  2. appium for ios 的资料确实不多,你可以参考官方文档(github 的或者官方网站的),官方讨论区 (https://discuss.appium.io/) 等,testerhome 也有不少好文的,你也可以搜索一下。总的来说,appium 作为 ios 和 android 通用的框架,大部分地方都是通用的,但有些特有的地方(如应用签名、使用 ios predicate)需要通过学习一些 ios 开发知识来补充(我也正在学习中)。

  3. 如何入门 appium:我的入门方法:自己搞个简单 app(学习应用开发),通过官方 sample-code 学习编写简单的脚本(学习 webdriver API),学习其他流行的移动开发框架(了解某些地方 appium 为何如此设计/如此使用,共有的就是最需要学习的),测试自己开发或市面现有的复杂 app(了解如何测试一个实际应用。实际应用总会有各种自定义控件,学习测试自定义控件才是落地的)。

最后说一点:国外网站大多是英文,所以英文水平也是必备的。每次学习到一个知识点最好写一篇博客/帖子记录一下,一方面方便后面自己查阅,另一方面也是知识库储备。

#6 楼 @cosyman 之前都是直接用 EXE 文件运行 appium,现在想在 jenkins 里部署 appium,命令行启动的时候卡在 chromedriver 安装了,请问这块怎么手动做呢?或者有可用的代理也麻烦告诉一下

#23 楼 @sunflower
如果用 nodejs npm 安装 appium,chromedriver 是被包含进去的,不会直接去 chromedriver 站点下载

guodeMacBook-Pro:appium guozhimu$ sudo ./bin/authorize-ios.js
Enabling DevToolsSecurity
Updating security db for developer access
Granting access to built-in simulator apps
WARN Finding XcodePath by symlink because TypeError: Invalid attempt to destructure non-iterable instance
error: uncaughtException: Arguments to path.resolve must be strings date=Sat Aug 29 2015 17:08:28 GMT+0800 (CST), pid=12268, uid=0, gid=0, cwd=/Users/guozhimu/appium, execPath=/usr/local/bin/node, version=v0.12.7, argv=[node, /Users/guozhimu/appium/bin/authorize-ios.js], rss=127705088, heapTotal=108155392, heapUsed=74206384, loadavg=[1.17138671875, 1.529296875, 1.68115234375], uptime=282618, trace=[column=13, file=path.js, function=Object.posix.resolve, line=439, method=posix.resolve, native=false, column=21, file=/Users/guozhimu/appium/grunt-helpers.js, function=null, line=257, method=null, native=false, column=17, file=/Users/guozhimu/appium/node_modules/q/q.js, function=null, line=1920, method=null, native=false, column=17, file=/Users/guozhimu/appium/node_modules/q/q.js, function=flush, line=110, method=null, native=false, column=11, file=node.js, function=process._tickDomainCallback, line=381, method=_tickDomainCallback, native=false], stack=[TypeError: Arguments to path.resolve must be strings, at Object.posix.resolve (path.js:439:13), at /Users/guozhimu/appium/grunt-helpers.js:257:21, at /Users/guozhimu/appium/node_modules/q/q.js:1920:17, at flush (/Users/guozhimu/appium/node_modules/q/q.js:110:17), at process._tickDomainCallback (node.js:381:11)]

ios 授权提示这个,怎么解

#25 楼 @chungeguo 这个我没遇到过。。。看起来是 Xcode path 有问题。你的 Xcode 有打开过吗?
如果还有问题,你可以上 appium 的项目主页搜一下。

问题:
执行./reset.sh 后,报错
Running "configAndroidBootstrap" task
Fatal error: Could not find Android SDK, make sure to export ANDROID_HOME
---- FAILURE: reset.sh exited with status 1 ----

求解

https://github.com/testerhome/appium.git 楼主 这个代码库下载哪个?还是都要下载啊?

#29 楼 @luckgirl 这个代码库有很多个?不明白你的问题。。。

嗯嗯 感看到 上面可以下载压缩包 谢谢你啊

#32 楼 @dodo 官方最新的代码,已经不用 reset.sh 了

谢谢解答,@lihuazhang 安装过程中直接跳过 3.1 运行 appium 目录下的 reset.sh ?尝了几次好想有问题

#34 楼 @dodo 你用的是什么源码?

#36 楼 @dodo

rm -rf node-modules
npm install
gulp transpile

@lihuazhang 安装之后,appium 文件里 test 中 unit 和 functional 都没有了,单元测试和功能测试都放 test 了吗?appium 内部文件改变还是比较大

@chenhengjie123 楼主,我一直卡在这,确认能上国外网络

用国内的源
#40 楼 @jira

#41 楼 @lihuazhang 能详细说下么?怎么切换国内源?

#42 楼 @jira 你搜索下 tnpm

#42 楼 @jira 这个。。。。。能自己 google 就自己 google 额。。。

#44 楼 @monkey 折腾好几天了 ~~ 还是报错

sudo cnpm install -g appium
[babel-core@5.8.24] deprecate: Babel 5 is no longer being maintained. Upgrade to Babel 6.
[fsevents@1.0.11] download from binary mirror: {"module_name":"fse","module_path":"./lib/binding/{configuration}/{node_abi}-{platform}-{arch}/","remote_path":"./v{version}/","package_name":"{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz","host":"https://npm.taobao.org/mirrors/fsevents"}
[line-numbers@0.2.0] deprecate: Copy its ~20 LOC directly into your code instead.
[appium@1.5.2] link /usr/local/bin/appium@ -> ../lib/node_modules/.appium_npminstall/appium/1.5.2/appium/build/lib/main.js
[appium@1.5.2] link /usr/local/bin/authorize-ios@ -> ../lib/node_modules/.appium_npminstall/appium/1.5.2/appium/node_modules/.bin/authorize-ios
[appium@*] installed at node_modules/.appium_npminstall/appium/1.5.2/appium (0 packages, use 43s, speed 268.92kB/s, json 3.61MB, tarball 7.73MB)
excute post install scripts...
[fsevents@1.0.11] scripts.install: "node-pre-gyp install --fallback-to-build" at /usr/local/lib/node_modules/.appium_npminstall/fsevents/1.0.11/fsevents
node-pre-gyp http GET https://npm.taobao.org/mirrors/fsevents/v1.0.11/fse-v1.0.11-node-v46-darwin-x64.tar.gz
node-pre-gyp http 200 https://npm.taobao.org/mirrors/fsevents/v1.0.11/fse-v1.0.11-node-v46-darwin-x64.tar.gz
[fsevents] Success: "/usr/local/lib/node_modules/.appium_npminstall/fsevents/1.0.11/fsevents/lib/binding/Release/node-v46-darwin-x64/fse.node" is installed via remote
[fsevents@1.0.11] scripts.install success, use 942ms
[appium-selendroid-driver@1.3.3] scripts.install: "node ./bin/install.js" at /usr/local/lib/node_modules/.appium_npminstall/appium-selendroid-driver/1.3.3/appium-selendroid-driver
dbug AndroidDriver Getting Java version
info SelendroidInstaller Ensuring /usr/local/lib/node_modules/.appium_npminstall/appium-selendroid-installer/0.2.0/appium-selendroid-installer/selendroid/download exists
info SelendroidInstaller Downloading Selendroid standalone server version 0.17.0 from https://github.com/selendroid/selendroid/releases/download/0.17.0/selendroid-standalone-0.17.0-with-dependencies.jar --> /usr/local/lib/node_modules/.appium_npminstall/appium-selendroid-installer/0.2.0/appium-selendroid-installer/selendroid/download/selendroid-server.jar
info AndroidDriver Java version is: 1.7.0_71

/usr/local/lib/node_modules/.appium_npminstall/request-promise/0.4.3/request-promise/lib/errors.js:11
Error.captureStackTrace(this);
^
RequestError: Error: read ETIMEDOUT
at new RequestError (/usr/local/lib/node_modules/.appium_npminstall/request-promise/0.4.3/request-promise/lib/errors.js:11:15)
at Request.RP$callback as _callback
at self.callback (/usr/local/lib/node_modules/.appium_npminstall/request/2.72.0/request/request.js:200:22)
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)
at Request.onRequestError (/usr/local/lib/node_modules/.appium_npminstall/request/2.72.0/request/request.js:831:8)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at TLSSocket.socketErrorListener (_http_client.js:256:9)
at emitOne (events.js:77:13)
at TLSSocket.emit (events.js:169:7)
at emitErrorNT (net.js:1253:8)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
Error: post install error, please remove node_modules before retry!
Run "sh -c node ./bin/install.js" error, exit code 1
Error: post install error, please remove node_modules before retry!
Run "sh -c node ./bin/install.js" error, exit code 1
at ChildProcess. (/usr/local/lib/node_modules/cnpm/node_modules/npminstall/node_modules/runscript/index.js:67:21)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:827:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

#44 楼 @monkey 站长能指点下么 哈哈`~

#45 楼 @jira 请使用 markdown!!!!!!!

#25 楼 @chungeguo 问一下,你的这个问题解决了吗?我也遇到这个问题了,网上没找到解决办法

我都装好了,不过运行一个 demo 时报错,appium 报错日志:info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName)","origValue":"The following desired capabilities are required, but were not provided: platformName, deviceName"},"sessionId":null},可是我启动 appium 时是:info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"avd":"android4.4.2","deviceName":"Android Emulator","platformName":"Android","platformVersion":"19","automationName":"Appium"},代码如下:capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "19");
capabilities.setCapability("deviceName", "Android Emulator");请问为啥还报那个错误呢?

#50 楼 @xzb 把你完整的代码发上来。 appium 版本号也发一下。

楼主大神及各位大神,求教下,安装失败,报错:Invalid or unsupported zip format. No END header found,有碰到过的吗,要怎么解决?感谢

$ npm config set registry=http://registry.npmjs.org

$ npm install -g appium

/usr/local/bin/appium -> /usr/local/lib/node_modules/appium/build/lib/main.js
/usr/local/bin/authorize-ios -> /usr/local/lib/node_modules/appium/node_modules/.bin/authorize-ios

> appium-chromedriver@2.9.2 install /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver
> node install-npm.js

info Chromedriver Install Installing Chromedriver version '2.21' for platform 'mac' and architecture '32'
info Chromedriver Install Opening temp file to write chromedriver_mac32 to...
info Chromedriver Install Downloading http://chromedriver.storage.googleapis.com/2.21/chromedriver_mac32.zip...
info Chromedriver Install Writing binary content to /var/folders/50/xqp4_clx0llb18dcw2jtqngw0000gp/T/2016910-26076-x86shc.nxm6nd0a4i/chromedriver_mac32.zip...
info Chromedriver Install Extracting /var/folders/50/xqp4_clx0llb18dcw2jtqngw0000gp/T/2016910-26076-x86shc.nxm6nd0a4i/chromedriver_mac32.zip to /var/folders/50/xqp4_clx0llb18dcw2jtqngw0000gp/T/2016910-26076-x86shc.nxm6nd0a4i/chromedriver_mac32
Invalid or unsupported zip format. No END header found
/usr/local/lib
└── (empty)

npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "appium"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! appium-chromedriver@2.9.2 install: `node install-npm.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the appium-chromedriver@2.9.2 install script 'node install-npm.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the appium-chromedriver package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install-npm.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs appium-chromedriver
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls appium-chromedriver
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/chenjiwang/appium_github_code/appium/npm-debug.log
npm ERR! code 1

#52 楼 @xcsky 已解决,怀疑原因是被墙的原因导致不能正常下载,另换了个 *** 再装就装好了。谢谢大家

#51 楼 @chenhengjie123 版本:appium1.4.16、完整代码如下:
package com.glen.demo;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.File;
import java.net.URL;
import java.util.List;

public class ContactsTest {
private WebDriver driver;

@Before
public void setUp() throws Exception {
//set up appium
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps/ContactManager");
File app = new File(appDir, "ContactManager.apk");

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "19");
capabilities.setCapability("deviceName", "Android Emulator");

driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@After
public void tearDown() throws Exception {
driver.quit();
}

@Test
public void addContact(){
WebElement el = driver.findElement(By.name("Add Contact"));
el.click();
List textFieldsList = driver.findElements(By.tagName("textfield"));
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.findElement(By.name("Save")).click();
}

public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
private RemoteTouchScreen touch;

public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
touch = new RemoteTouchScreen(getExecuteMethod());
}

public TouchScreen getTouch() {
return touch;
}
}
}

另外:配置安卓模拟器过程中少了一个 GoogleMap APIs(ARM system image)不知道对此有没有影响。

#54 楼 @xzb

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("platformName", "Android"); 
capabilities.setCapability("platformVersion", "19");
capabilities.setCapability("deviceName", "Android Emulator");

driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

你既没给 apk 路径,也没给 activity 之类的信息,appium 不知道要测什么应用。

PS:以后麻烦用 md 排版吧,要不代码没有缩进和着色看起来真心累。md 怎么用请看回复框右下角的 排版说明 。

#55 楼 @chenhengjie123 谢谢你,我看了视频,明白你的意思了,因为我之前没学过 Android,可是我导入路径之后,appium 没有自动识别 package 和 activity 信息,我百度了,用 aapt 命令,但是我 SDK 下没有这个命令,会不会影响自动识别,另外其他方法说是打开应用,我试了也不行。大神有办法吗?

#55 楼 @chenhengjie123 多谢你啊,真是少了那个文件夹,可以了

#55 楼 @chenhengjie123 哥们,Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.remote.HttpCommandExecutor.(Ljava/util/Map;Ljava/net/URL;Lorg/openqa/selenium/remote/http/HttpClient$Factory;) V
at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:43)
at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:55)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:131)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:92)
at com.glen.demo.ContactsTest.main(ContactsTest.java:44)
报这个错,是不是 java client 这个 jar 包的版本不对啊,我是 4.1.2 的。

#58 楼 @xzb 报错的是啥代码。。。

#59 楼 @chenhengjie123

package com.glen.demo;

import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.net.URL;
import java.util.List;

public class ContactsTest{
    private static void login(AppiumDriver driver) {
        // TODO Auto-generated method stub

    }

    public static void main(String[] args) throws Exception {
        AndroidDriver driver;

        //File app=new File("C:\\Users\\zoucw\\Desktop\\WeChat_880.apk");
        DesiredCapabilities capabilities=new DesiredCapabilities();

        //capabilities.setCapability("app",app.getAbsolutePath());
        capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
        capabilities.setCapability("devicename","Android Emulator");
        capabilities.setCapability("platformVersiom","4.4");
        capabilities.setCapability("platformName","Android");

        capabilities.setCapability("appPackage","com.tencent.mm");
        capabilities.setCapability("appActivity",".ui.launcherUI");

        capabilities.setCapability("unnicodeKeyboard","Ture");
        capabilities.setCapability("resetKeyboard","Ture");
        capabilities.setCapability("noSign","Ture");

        driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

        Thread.sleep(5000);
        try{
            login(driver);
            Thread.sleep(5000);
        } catch (Exception e){
            e.printStackTrace();

        }finally{
            Thread.sleep(5000);
            driver.quit();
        }

    }


}

#59 楼 @chenhengjie123 是不是 java client 的包不对啊 我试了 4.1.2 的 还有 1.4 1.2 的 都不行

#61 楼 @xzb 额,你具体哪行出错?

java client 的包你直接拿官方的(https://mvnrepository.com/artifact/io.appium/java-client/4.1.2)应该没问题。

#62 楼 @chenhengjie123 代码不出错,运行报错了,现在我保留的是 java client4.1.2 和 selenium java-2.5.3 和 selenium java-standalone 2.5.3 这三个包

#62 楼 @chenhengjie123 现在我只保留三个 jar 包 其他版本删除了,然后又报错了

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'zoucw-PC', ip: '172.27.35.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
    at com.glen.demo.ContactsTest.main(ContactsTest.java:44)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'zoucw-PC', ip: '172.27.35.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'
Driver info: driver.version: AndroidDriver
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:84)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
    ... 11 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
    at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:144)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
    ... 12 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
    at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
    ... 25 more

#62 楼 @chenhengjie123 会不会还是 jar 包问题 2.5.3 是不是太高了

#62 楼 @chenhengjie123 或者正常是哪三个包的版本啊,我下载下来试试

#64 楼 @xzb 你的 appium server 有启动了吗?有报错吗?

#67 楼 @chenhengjie123 info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)

error: The following desired capabilities are required, but were not provided: deviceName
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: The following desired capabilities are required, but were not provided: deviceName
这是 appium 运行的错误

#67 楼 @chenhengjie123 不好意思,发错了,重新发一个

info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersiom":"4.4","platformName":"Android","unnicodeKeyboard":"Ture","browserName":"","appActivity":".ui.launcherUI","devicename":"Android Emulator","noSign":"Ture","resetKeyboard":"Ture","appPackage":"com.tencent.mm"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
error: The following desired capabilities are required, but were not provided: deviceName
info: [debug] Error: The following desired capabilities are required, but were not provided: deviceName

#67 楼 @chenhengjie123

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 388 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'zoucw-PC', ip: '172.27.35.69', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_75'
Driver info: io.appium.java_client.android.AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
    at com.glen.demo.ContactsTest.main(ContactsTest.java:44)
这是java运行报错

#70 楼 @xzb A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)

这个报错和你最初的报错不是一样嘛。。。

麻烦描述问题的时候描述清楚你的脚本代码、具体出错代码行、具体出错信息吧。只给其中一个都无法帮你定位问题。

#71 楼 @chenhengjie123 原来是需要 eclipse clean 就行了,晕死,谢谢你

陈恒捷 加入 Testerhome 后的成长经历分享 中提及了此贴 01月10日 09:39
陈恒捷 Appium 开发环境搭建合集 中提及了此贴 02月22日 12:42
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册