appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 758 forks source link

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 #1504

Open RehanProgrammer opened 3 years ago

RehanProgrammer commented 3 years ago

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]

KazuCocoa commented 3 years ago

What's the output when you run the command manually?

KazuCocoa commented 3 years ago

Perhaps loglevel info/debug helps at first.

RehanProgrammer commented 3 years ago

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

RehanProgrammer commented 3 years ago

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

KazuCocoa commented 3 years ago

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 ?

RehanProgrammer commented 3 years ago

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

prabhurohith commented 2 years ago
        service = new AppiumServiceBuilder()
                .withIPAddress("127.0.0.1")
                .usingAnyFreePort()
                **.withTimeout(Duration.ofSeconds(300))**
                .build();
        service.start();

Try adding timeout

drjoeyoussef commented 1 year ago

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

Krishna077 commented 1 year ago

@drjoeyoussef try adding withTimeout(Duration.ofSeconds(200)) in your AppiumServiceBuilder(). It should do the trick

drjoeyoussef commented 1 year ago

@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.

Krishna077 commented 1 year ago

@drjoeyoussef Yes I tried it on my Mac. Can you share your builder method?

drjoeyoussef commented 1 year ago

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

}
Krishna077 commented 1 year ago

@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

drjoeyoussef commented 1 year ago

@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.
[Appium] spawn npm ENOENT
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: [Appium] spawn npm ENOENT

    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: [Appium] spawn npm ENOENT

    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
===============================================
Krishna077 commented 1 year ago

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

RucheeSadani commented 1 year ago

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: [Appium] spawn npm ENOENT"

Can someone please help me

drjoeyoussef commented 1 year ago

@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.

RucheeSadani16 commented 1 year ago

@Krishna077 can you suggest some other solution for the same ?

sumit-global commented 1 year ago

I am also facing same issue, did anyone manage to get fix?

sayed2 commented 1 year ago

I am also facing the same issue. Does anyone has a solution that works?

testnbebest commented 1 year ago

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

appiumServerLogs.txt

testnbebest commented 1 year ago

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

appiumServerLogs.txt

samarthpatil747 commented 1 year ago

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: [Appium] spawn npm ENOENT

at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:187)
at iosjombay.Assessment.AppiumBasics.AppiumTest(AppiumBasics.java:27)
sp090 commented 1 year ago

Any update on this issue

nvn27 commented 1 year ago

Facing same issue; tried different appium versions.

ManjuathQA commented 2 months ago

Im getting this reponse Anyone please help me to resolve this issue

This is my code import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; import org.testng.annotations.Test;

import java.io.File; import java.time.Duration;

public class AppiumServiceAutomatic {

public AppiumDriverLocalService service;

@Test
public void serverConfig()
{
      service = new AppiumServiceBuilder()
            .withAppiumJS(new File("C:\\Users\\manjunath.muni\\AppData\\Roaming\\npm\\node_modules\\appium\\lib\\main.js"))
            .withIPAddress("127.0.0.1")
              .usingAnyFreePort()
              .withTimeout(Duration.ofSeconds(300))
             .build();
      service.start();
    System.out.println("SERVER STARTED");

}

}

SLF4J(W): No SLF4J providers were found. SLF4J(W): Defaulting to no-operation (NOP) logger implementation SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details. SLF4J(W): Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier. SLF4J(W): Ignoring binding found at [jar:file:/C:/Users/manjunath.muni/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J(W): See https://www.slf4j.org/codes.html#ignoredBindings for an explanation. (node:20300) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use node --trace-warnings ... to show where the warning was created) C:\Users\manjunath.muni\AppData\Roaming\npm\node_modules\appium\lib\main.js:3 import {WebSocketServer} from 'ws'; ^^^^^^

SyntaxError: Cannot use import statement outside a module at wrapSafe (node:internal/modules/cjs/loader:1281:20) at Module._compile (node:internal/modules/cjs/loader:1321:27) at Module._extensions..js (node:internal/modules/cjs/loader:1416:10) at Module.load (node:internal/modules/cjs/loader:1208:32) at Module._load (node:internal/modules/cjs/loader:1024:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12) at node:internal/main/run_main_module:28:49

Node.js v20.16.0 Exception in thread "main" io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: Appium HTTP server is not listening at http://0.0.0.0:34922/ after 20000 ms timeout. Consider increasing the server startup timeout value and check the server log for possible error messages occurrences. Node.js executable path: C:\Program Files\nodejs\node.exe Arguments: [C:\Users\manjunath.muni\AppData\Roaming\npm\node_modules\appium\lib\main.js, --port, 34922, --address, 0.0.0.0, --log, C:\Users\manjunath.muni\eclipse-workspace\MobileAutomation\AppiumServerLogs.txt] Server log: (node:20300) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use node --trace-warnings ... to show where the warning was created) C:\Users\manjunath.muni\AppData\Roaming\npm\node_modules\appium\lib\main.js:3 import {WebSocketServer} from 'ws'; ^^^^^^

SyntaxError: Cannot use import statement outside a module at wrapSafe (node:internal/modules/cjs/loader:1281:20) at Module._compile (node:internal/modules/cjs/loader:1321:27) at Module._extensions..js (node:internal/modules/cjs/loader:1416:10) at Module.load (node:internal/modules/cjs/loader:1208:32) at Module._load (node:internal/modules/cjs/loader:1024:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12) at node:internal/main/run_main_module:28:49

Node.js v20.16.0

at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:192)
at practice.AppiumServer.main(AppiumServer.java:48)

Caused by: io.appium.java_client.service.local.AppiumServerAvailabilityChecker$ConnectionTimeout: ConnectionTimeout at io.appium.java_client.service.local.AppiumServerAvailabilityChecker.waitUntilAvailable(AppiumServerAvailabilityChecker.java:72) at io.appium.java_client.service.local.AppiumDriverLocalService.ping(AppiumDriverLocalService.java:144) at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:185) ... 1 more Caused by: java.net.ConnectException: Connection refused: no further information at java.base/sun.nio.ch.Net.pollConnect(Native Method) at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:547) at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602) at java.base/java.net.Socket.connect(Socket.java:633) at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:178) at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:534) at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:639) at java.base/sun.net.www.http.HttpClient.(HttpClient.java:282) at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:387) at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:409) at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1309) at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242) at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128) at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1057) at io.appium.java_client.service.local.AppiumServerAvailabilityChecker.connectToUrl(AppiumServerAvailabilityChecker.java:79) at io.appium.java_client.service.local.AppiumServerAvailabilityChecker.waitUntilAvailable(AppiumServerAvailabilityChecker.java:61) ... 3 more

Process finished with exit code 1