Appium:错误:无法启动Appium会话,错误是:错误:'java -version'失败

时间:2016-01-01 09:39:36

标签: java android eclipse appium

我在@Test方法中写了下面的代码:

File app = new File("E:\\AppiumWorkspace\\apk\\redBus.apk");
   DesiredCapabilities capabilities = new DesiredCapabilities();
        // capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
         capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"XOLO Q1010");
         capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.2.2");
         capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
     capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

       capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "in.redbus.android");
        capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "in.redbus.android.activity.SplashScreen");


        dr = new AndroidDriver<MobileElement> (new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

        dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

关于从eclipse运行代码我在eclipse上遇到错误:

> Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --full-reset --platform-name Android --platform-version 17 --automation-name Appium --log-no-color
> info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: [debug] Non-default server args: {"address":"127.0.0.1","fullReset":true,"logNoColors":true,"platformName":"Android","platformVersion":"17","automationName":"Appium"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.2.2","app":"E:\\AppiumWorkspace\\apk\\redBus.apk","deviceName":"XOLO Q1010","platformName":"Android","appActivity":"in.redbus.android.activity.SplashScreen","appPackage":"in.redbus.android"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
> info: [debug] Using local app from desired caps: E:\AppiumWorkspace\apk\redBus.apk
> info: [debug] Creating new appium session 308ffbc6-2e50-4c9d-bffc-442500683e20
> 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: C:\Windows\system32\cmd.exe /s /c "java -version"
> 'java' is not recognized as an internal or external command,
> operable program or batch file.
> 
> info: [debug] Error: 'java -version' failed. Error: Command failed: C:\Windows\system32\cmd.exe /s /c "java -version"
> 'java' is not recognized as an internal or external command,
> operable program or batch file.
> 
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
>     at ChildProcess.exithandler (child_process.js:758:5)
>     at ChildProcess.emit (events.js:110:17)
>     at maybeClose (child_process.js:1016:16)
>     at Socket.<anonymous> (child_process.js:1184:11)
>     at Socket.emit (events.js:107:17)
>     at Pipe.close (net.js:484:11)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"java -version\"\n'java' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n)","origValue":"'java -version' failed. Error: Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"java -version\"\n'java' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 230.274 ms - 526

我重新安装java坚果它没有帮助。我收到同样的错误。

在Eclipse上我有以下错误:

FAILED: testApp
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: 'java -version' failed. Error: Command failed: C:\Windows\system32\cmd.exe /s /c "java -version"
'java' is not recognized as an internal or external command,
operable program or batch file.
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 503 milliseconds

我已经验证了ANDROID_HOME和JAVA_HOME路径,这些路径指向正确的位置。我在cmd上运行了adb devices命令,它给了我正确的输出。

任何人都可以帮我解决这个问题。

以下是PATH的内容:

    C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;
C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;
C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\SWTOOLS\ReadyApps;C:\Program Files (x86)\Common Files\Lenovo;
C:\Program Files (x86)\OpenVPN\bin;C:\Program Files\nodejs\;
C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Skype\Phone\;
C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;%ANDROID_HOME%\tools;
%ANDROID_HOME%\platform-tools;%JAVA_HOME%;%JAVA_HOME%\bin;%ANDROID_HOME%;

3 个答案:

答案 0 :(得分:0)

您是否已将bin路径添加到路径环境变量中?

答案 1 :(得分:0)

  1. 您是否可以在任何目录位置的cmd中尝试java -version,并将结果与​​Eclipse用于在Project Settings.
  2. 中构建的项目的java版本相匹配
  3. 未创建会话,因为您的项目需要一个目前在您的系统上不可用的Java版本。

答案 2 :(得分:0)

我希望一些系统内置库路径丢失。请添加它们并试一试。 对于Ex:它应该具有系统指定的默认路径。我希望有些路径可能会被删除。请添加并尝试。 的 For EX: PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v 1.0\;C:\Program Files\Windows Live\Shared