Appium 新手求助,appium 运行报 java -version failed 的问题!

伊凡 · 2016年07月08日 · 最后由 lxp_1023 回复于 2017年09月21日 · 2039 次阅读
  1. 已经搜索了论坛里面所有类似的问题 都试过了都没有解决

  2. 检查了所有的环境变量配置问题,也都正常,截图如下:

    3、代码如下:

require "rubygems"
require "appium_lib"
require "minitest/autorun"

describe "Basic Android Test" do
    def caps
        {
            caps: {
                appiumVersion: "1.4.13",
                platformName: "Android",
                platformVersion: "4.4",
                deviceName: "test",
                app: "C:/adt-bundle/XJ.apk",
                name: "Basic Android Native Test",
            }
        }
    end

    before do
        @driver = Appium::Driver.new(caps)
        @driver.start_driver
    end

    after do
        @driver.driver_quit
    end

    describe "when I open the app" do
        it "should be able to navigate to the Action Bar" do
            el = @driver.find_element :accessibility_id, "App"
            el
            texts = @driver.find_elements :class_name, "android.widget.TextView"
            texts[1].text.must_equal "gonghao"
        end
    end
end

4.命令行日志报错内容如下:

C:\adt-bundle>ruby test.rb
Run options: --seed 45047

# Running:

E

Finished in 3.193182s, 0.3132 runs/s, 0.0000 assertions/s.

  1) Error:
Basic Android Test::when I open the app#test_0001_should be able to navigate to
the Action Bar:
Selenium::WebDriver::Error::ServerError: status code 500
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/response.rb:73:in `assert_ok'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/response.rb:34:in `initialize'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/http/common.rb:78:in `new'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/http/common.rb:78:in `create_response'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/http/default.rb:90:in `request'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/http/common.rb:59:in `call'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/bridge.rb:664:in `raw_execute'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/bridge.rb:122:in `create_session'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/remote/bridge.rb:87:in `initialize'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/common/driver.rb:56:in `new'
    C:/Ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.48.1/lib/selenium/we
bdriver/common/driver.rb:56:in `for'

5、appium 运行日志报错如下:

info: --> POST /wd/hub/session {"desiredCapabilities":{"appiumVersion":"1.4.13",
"platformName":"Android","platformVersion":"4.4","deviceName":"test","app":"C:/a
dt-bundle/XJ.apk"}}
info: Client User-Agent string: appium/ruby_lib/8.0.0
info: [debug] The following desired capabilities were provided, but not recogniz
ed by appium. They will be passed on to any other services running on this serve
r. : appiumVersion
info: [debug] No appActivity desired capability or server param. Parsing from ap
k.
info: [debug] No appPackage desired capability or server param. Parsing from apk
.
info: [debug] Using local app from desired caps: C:\adt-bundle\XJ.apk
info: [debug] Creating new appium session 1fa9ecd4-fafc-4c96-ba8b-c4fd90239361
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: 'java -version' failed
. Error: Command failed: java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) Client VM (build 25.91-b15, mixed mode)

info: [debug] Error: 'java -version' failed. Error: Command failed: java version
 "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) Client VM (build 25.91-b15, mixed mode)

    at [object Object].<anonymous> (C:\Program Files\Appium\node_modules\appium\
lib\devices\android\android-common.js:1057:17)
    at ChildProcess.exithandler (child_process.js:641:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: 'java -version' failed. Err
or: Command failed: java version \"1.8.0_91\"\r\nJava(TM) SE Runtime Environment
 (build 1.8.0_91-b15)\r\nJava HotSpot(TM) Client VM (build 25.91-b15, mixed mode
)\r\n)","origValue":"'java -version' failed. Error: Command failed: java version
共收到 10 条回复 时间 点赞

我觉得还是 java 配置问题,手工敲命令 java -version 报错吗?
下面是我的配置信息。
• 变量名:JAVA_HOME
• 变量值:C:\Program Files (x86)\Java\jdk1.8.0_65 // 要根据自己的实际路径配置
• 变量名:CLASSPATH
• 变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; //记得前面有个"."
• 变量名:Path
• 变量值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

运行这两个命令看看结果
where java
%JAVA_HOME%\bin\java -version

你是如何运行 Appium 的?

#3 楼 @lihuazhang 在命令行运行 appium

#4 楼 @skyice77 Appium 啥版本?

#5 楼 @lihuazhang 1.4.13 里面的代码 是这样的:

androidCommon.getJavaVersion = function (cb) {
  var extractVersion = function (err, stdout, stderr) {
    var javaVersion = null;
    if (err) {
      return cb(new Error("'java -version' failed. " + err));
    } else if (stderr) {
      javaVersion = this.parseJavaVersion(stderr);
    }
    if (javaVersion === null) {
      return cb(new Error("Could not get the Java version. Is Java installed?"));
    }
    return cb(null, javaVersion);
  }.bind(this);

  exec("java -version", extractVersion);
};

#4 楼 @skyice77 升级个版本吧。 这里感觉有点莫名其妙啊。 java -version 已经返回数据了。但是 exec("java -version", extractVersion); 却执行出错了。

貌似这个问题 windows 下出现概率比较高,应该和 exec 的环境有关吧。

#7 楼 @lihuazhang
#8 楼 @chenhengjie123

不是很清楚。有可能和 node 有关系。

请问你这个问题最后怎么解决的啊,我现在也遇到同样的问题了,java 环境是好的,但是仍报这个错误

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册