简体   繁体   中英

Appium: error: Failed to start an Appium session, err was: Error: 'java -version' failed

I have written below code in @Test method:

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);

On Running code from eclipse I am getting below error on 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

I re-installed java nut it did not helped. I received same error.

On Eclipse I am having below error:

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

I have verified ANDROID_HOME and JAVA_HOME path and those are pointing to correct locations. I ran adb devices command on cmd and it gives me correct output.

Can anyone please help me sorting out this problem.

Following is the content of 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%;

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

  1. Could you try java -version from the cmd at any directory location once and match the result with the java version that Eclipse is using for the project to build in Project Settings.
  2. Session is not created because your project requires a java version which is not available on your system as of now.

I hope some of the system inbuilt library paths are missing. Please add them and try it out. For Ex: It should be having system specified default paths. i hope some path might got deleted. Please add it and try. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM