Unable to start Appium Server

I am trying to start Appium server programmatically. While doing that am getting error as NodeJS is either not installed or its executable not present in PATH

When i am trying to start appium server manually then the Sever starts without any issue as well as i able to execute test cases. But when i am trying to start the server programmatically then it gives error.

Error:-

[RemoteTestNG] detected TestNG version 7.3.0
FAILED: View_Earnings
io.appium.java_client.service.local.InvalidServerInstanceException: NodeJS is either not installed or its executable not present in PATH
at io.appium.java_client.service.local.AppiumServiceBuilder.validatePath(AppiumServiceBuilder.java:127)
at io.appium.java_client.service.local.AppiumServiceBuilder.findBinary(AppiumServiceBuilder.java:137)
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:180)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:87)
at MobileAppAutomation.AppiumFramework.Config.startAppiumServer(Config.java:53)
at ViewEarnings.TC_View_Earnings.View_Earnings(TC_View_Earnings.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0

===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0

Code :-

public static AppiumDriverLocalService service;

public AppiumDriverLocalService startAppiumServer() throws IOException, InterruptedException {

Runtime.getRuntime().exec(“taskkill /F /IM node.exe”);
Thread.sleep(1000);

boolean flag = checkIfAppiumServerIsRunning(4723);
if(!flag) {

  service = AppiumDriverLocalService.buildDefaultService();
  service.start();
  
  //to stop all ports on system use this command taskkill /F /IM node.exe

}
return service;

}

Even i found a workaround as follows but the issue is i not able to locate Appium node and Appium JS path as shown in below code.

String Appium_Node_Path=“C:/Program Files/Appium/node.exe”;
String Appium_JS_Path=“C:/Program Files/Appium/node_modules/appium/bin/appium.js”;
AppiumDriverLocalService appiumService;

appiumService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().
usingAnyFreePort().usingDriverExecutable(new File(Appium_Node_Path)).
withAppiumJS(new File(Appium_JS_Path)));
appiumService.start();

Can you please help me to overcome this issue?

Thanks in avance.

Hey, Did you get a solution to this. I have the same issue
:pensive: