java-client
java-client copied to clipboard
io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js
Description
HI, Im facing this issue of starting appium server programatically. I have gone through many other github threads about this same issue but to no luck.
Environment
Appium version: 1.21.0 (latest)
Node: v12.19.0
Details
I am calling the service on rest template. I tried many ways of starting an appium server programmatically but non worked. Please help
Code To Reproduce Issue
public class AppiumServer {
private static AppiumDriverLocalService server;
private int port;
public AppiumServer() {
server = buildAppiumServer();
}
private AppiumDriverLocalService buildAppiumServer() {
return new AppiumServiceBuilder().usingAnyFreePort()
.withIPAddress( "127.0.0.1" )
.withArgument( GeneralServerFlag.LOG_LEVEL, "error" )
.withArgument( GeneralServerFlag.SESSION_OVERRIDE )
.build();
}
public void start(){
this.server.start();
}
public void stop() {
this.server.stop();
}
public AppiumDriverLocalService get(){
return this.server;
}
}
Exception Stacktraces
Caused by: io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js, --port, 3784, --address, 127.0.0.1, --log-level, error, --session-override]
What's the output when you run the command manually?
Perhaps loglevel info/debug helps at first.
when i run the command "node /usr/local/lib/node_modules/appium/build/lib/main.js", appium starts on terminal. My node executable path is /usr/local/bin/node
Also my appium is installed globally via "npm i -g appium". On terminal, i can start the appium by running "appium". I am using jdk 11 in this case. I have also given read, write, execute permission to both directories
What about running the server like tests https://github.com/appium/java-client/blob/0e05078d0ae8e4bebb80080790712e933e2ea666/src/test/java/io/appium/java_client/android/BaseAndroidTest.java#L40 ?
I would like to start appium programmatically on a specific port. Is there anyway i can do that like the example above. I am developing an application which needs to start appium
service = new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingAnyFreePort()
**.withTimeout(Duration.ofSeconds(300))**
.build();
service.start();
Try adding timeout
I have the same issue, did anyone find a solution for it?
I'm getting this error:
io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js, --port, 4723, --address, 0.0.0.0] Process output: [Appium]spawn npm ENOENT
@drjoeyoussef try adding withTimeout(Duration.ofSeconds(200))
in your AppiumServiceBuilder(). It should do the trick
@Krishna077 Thank you for reply dear! I actually tried it but it's not working on the mac, I've been told that there is no solution for the mac for now, I don't know if you've tried it also on a mac.
@drjoeyoussef Yes I tried it on my Mac. Can you share your builder method?
@Krishna077 I really appreciate your kindness and your help. That's the builder method:
public IOSDriver driver;
public AppiumDriverLocalService service;
@BeforeClass
public void ConfigureAppium() throws MalformedURLException
{
service = new AppiumServiceBuilder().withAppiumJS(new File("//usr//local//lib//node_modules//appium//build//lib//main.js"))
.withIPAddress("0.0.0.0").usingPort(4723). withTimeout(Duration.ofSeconds(200)).build();
service.start();
}
@drjoeyoussef AppiumJS path doesn’t look right. Could you check your path , you might need to remove extra / from the path and you have an extra space before your timeout
@Krishna077
I tried it like that
service = new AppiumServiceBuilder().withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withIPAddress("0.0.0.0").usingPort(4723).withTimeout(Duration.ofSeconds(200)).build();
service.start();
I got the same error:
[RemoteTestNG] detected TestNG version 7.4.0
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
[35m[Appium][39m [31mspawn npm ENOENT[39m
FAILED CONFIGURATION: @BeforeClass ConfigureAppium
io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js, --port, 4723, --address, 0.0.0.0]
Process output: [35m[Appium][39m [31mspawn npm ENOENT[39m
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:187)
at PracticeShpark.PracticeShpark.errors.ShparkBaseTest.ConfigureAppium(ShparkBaseTest.java:38)
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:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
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)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://127.0.0.1:4723/status] to be available after 200003 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:89)
at io.appium.java_client.service.local.AppiumDriverLocalService.ping(AppiumDriverLocalService.java:152)
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:174)
... 27 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:87)
... 29 more
SKIPPED CONFIGURATION: @AfterClass tearDown
SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: InBuiltAppTest
io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js, --port, 4723, --address, 0.0.0.0]
Process output: [35m[Appium][39m [31mspawn npm ENOENT[39m
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:187)
at PracticeShpark.PracticeShpark.errors.ShparkBaseTest.ConfigureAppium(ShparkBaseTest.java:38)
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:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
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)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://127.0.0.1:4723/status] to be available after 200003 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:89)
at io.appium.java_client.service.local.AppiumDriverLocalService.ping(AppiumDriverLocalService.java:152)
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:174)
... 27 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:87)
... 29 more
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 2
===============================================
===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 2
===============================================
Can you try the below : service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().withIPAddress("0.0.0.0").usingPort(Integer.parseInt("4723")).withTimeout(Duration.ofSeconds(200)).withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js")));
service.start();
I am also facing the same issue since yesterday before that it was working fine. Below is the code snippet that I have written AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File("//usr//local//lib//node_modules//appium//build//lib//main.js")) .withIPAddress("127.0.0.1").usingPort(4723).build(); service.start(); //Create object of Android driver UiAutomator2Options options = new UiAutomator2Options();
And below is the error :
"io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js, --port, 4723, --address, 127.0.0.1] Process output: [35m[Appium][39m [31mspawn npm ENOENT[39m"
Can someone please help me
@Krishna077 Thank you again for your help, I tried the code you sent me and I got the same error, do you think that there is some issue with the appium server on mac lately? I don't know honestly.
@Krishna077 can you suggest some other solution for the same ?
I am also facing same issue, did anyone manage to get fix?
I am also facing the same issue. Does anyone has a solution that works?
Working fine for me with Appium 2.0 on MacBook
### Java Code for Android
`package org.AutomationAcademy.baseTest;
import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.options.UiAutomator2Options; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; import io.appium.java_client.service.local.flags.GeneralServerFlag; import org.testng.annotations.Test;
import java.io.File; import java.net.MalformedURLException; import java.net.URL;
public class androidBaseTest {
public AppiumDriver driver;
public AppiumDriverLocalService service;
@Test
public void setUp() throws MalformedURLException {
service = new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withIPAddress("127.0.0.1")
.withLogFile(new File(System.getProperty("user.dir") + File.separator + "src"
+ File.separator + "test" + File.separator + "java" + File.separator + "org.AutomationAcademy"
+ File.separator + "resources" + File.separator + "logs" + File.separator + "appiumServerLogs.txt"))
.withArgument(GeneralServerFlag.LOCAL_TIMEZONE)
.usingPort(4723)
.build();
service.start();
service.clearOutPutStreams();
String appUrl = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "java"
+ File.separator + "org" + File.separator +"AutomationAcademy" + File.separator + "resources" + File.separator + "appFiles"
+ File.separator + "Android-MyDemoApp.apk";
UiAutomator2Options options = new UiAutomator2Options();
options.setDeviceName("Pixel_4");
options.setUdid("emulator-5554");
options.setAppPackage("com.saucelabs.mydemoapp.rn");
options.setAppActivity("com.saucelabs.mydemoapp.rn.MainActivity");
options.setApp(appUrl);
URL url = new URL("http://127.0.0.1:4723");
driver = new AndroidDriver(url, options);
System.out.println("App Launched Successfully");
driver.quit();
System.out.println("App terminated Successfully");
service.stop();
System.out.println("Services stopped Successfully");
}
}
`
Console Logs
SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. App Launched Successfully App terminated Successfully Services stopped Successfully
=============================================== Default Suite Total tests run: 1, Failures: 0, Skips: 0
Process finished with exit code 0
Appium Server Logs
Working fine for iOS App on Macbook
`package org.AutomationAcademy.baseTest;
import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.ios.options.XCUITestOptions; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; import io.appium.java_client.service.local.flags.GeneralServerFlag; import org.testng.annotations.Test;
import java.io.File; import java.net.MalformedURLException; import java.net.URL;
public class iOSBaseTest {
public AppiumDriver driver;
public AppiumDriverLocalService service;
@Test
public void setUp() throws MalformedURLException {
service = new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withIPAddress("127.0.0.1")
.withLogFile(new File(System.getProperty("user.dir") + File.separator + "src"
+ File.separator + "test" + File.separator + "java" + File.separator + "org" + File.separator +"AutomationAcademy"
+ File.separator + "resources" + File.separator + "logs" + File.separator + "appiumServerLogs.txt"))
.withArgument(GeneralServerFlag.LOCAL_TIMEZONE)
.usingPort(4723)
.build();
service.clearOutPutStreams();
service.start();
XCUITestOptions options = new XCUITestOptions();
options.setDeviceName("iPhone 14 Pro");
options.setUdid("F6AD3DA7-E6E1-4F6A-9DC7-B295E18B6FED");
options.setBundleId("com.saucelabs.mydemoapp.rn");
options.setCapability("usePrebuiltWDA", true);
URL url = new URL("http://127.0.0.1:4723");
driver = new IOSDriver(url, options);
System.out.println("App Launched Successfully");
driver.quit();
System.out.println("App terminated Successfully");
service.stop();
System.out.println("Services stopped Successfully");
}
} `
Console Logs
SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. App Launched Successfully App terminated Successfully Services stopped Successfully
=============================================== Default Suite Total tests run: 1, Failures: 0, Skips: 0
Process finished with exit code 0
Appium Server logs
Not working for below code getting same error
AppiumDriverLocalService service = new AppiumServiceBuilder() .usingDriverExecutable(new File("/usr/local/bin/node")) .withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js")) .withIPAddress("127.0.0.1").usingPort(4723) .withTimeout(Duration.ofSeconds(20)).build();
service.clearOutPutStreams();
service.start();
UiAutomator2Options options = new UiAutomator2Options();
options.setDeviceName("Samarth Simulator");
options.setApp(
"/users/alpha//Desktop//JavaBasics.java//jid/BasicJava//AssessmentApp//src//test//java//resources//Idev-Plus-v1.9.0-staging.apk");
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);
driver.quit();
service.stop();
======================================================================================== Getting below error: [RemoteTestNG] detected TestNG version 7.7.1 SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. FAILED: iosjombay.Assessment.AppiumBasics.AppiumTest io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/build/lib/main.js, --port, 4723, --address, 127.0.0.1] Process output: [35m[Appium][39m [31mspawn npm ENOENT[39m
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:187)
at iosjombay.Assessment.AppiumBasics.AppiumTest(AppiumBasics.java:27)
Any update on this issue
Facing same issue; tried different appium versions.