Error on trying to start appium server programatically

Please help me in fixing the issue for the following script

Check the script


package LetsStartAppium;

import java.io.IOException;

import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

@Test
public class AppiumStartandstop {

/**
 * @param args
 */

Process p;
//Set path of your node.exe file
//Progra~1 represents Program Files Folder.
String nodePath=“C:/Program Files (x86)/Appium”;
//Set path of appium.js
String appiumJSPath=“C:/Program Files (x86)/Appium/node_modules/appium/bin”;
String cmd=nodePath+" "+appiumJSPath;
AndroidDriver driver;

//Method responsible for starting appium server
public void appiumStart() throws IOException, InterruptedException
{
//Execute command string to start appium server
Runtime.getRuntime().exec(cmd);
//Provide wait time of 10mins to start appium server properly.
//if face any error(Could not start a new session…) then Increase
//this time to 15 to 30 sec
Thread.sleep(10000);
if(p!=null)
{
System.out.println(“Appium server is started now”);

}

}
//Method responsible
@Test
public void appiumStop()
{
if(p!=null)
{
p.destroy();
}
System.out.println(“Appium server is stopped now”);
}
}

Issue


java.io.IOException: Cannot run program “C:/Program”: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at LetsStartAppium.AppiumStartandstop.appiumStart(AppiumStartandstop.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:822)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1130)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 29 more

You’ll need to escape the spaces in your appiumJSPath:

Instead of above paths, try using below paths

String nodePath=“C:\Program Files (x86)\Appium”;
String appiumJSPath=“C:\Program Files (x86)\Appium\node_modules\appium\bin”;

let me know if this works.

Thanks Setu. But I already had a solution for it & it works.

I was missing a file in both the paths

String nodePath=“C:/Progra~2/Appium/node.exe”;

//Set path of appium.js

String appiumJSPath=“C:/Progra~2 /Appium/node_modules/appium/bin/appium.js”;

Another error in the path was that we cannot use space characters as in Program Files (x86) . So there is or an acronym for it “Progra~2”.

1 Like