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

Inability to start the Appium server programmatically failing in random fashion with the message: io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. #1927

Closed vnuta9 closed 1 year ago

vnuta9 commented 1 year ago

Description

Related to the topic "https://github.com/appium/java-client/blob/master/docs/The-starting-of-an-app-using-Appium-node-server-started-programmatically.md" applicable to Appium versions 1.xx, I am getting random failure(roughly 1 in every 3 times) of starting the Appium server programmatically.

Environment

Details

Irrespective of using any mobile device, Android or iOS, I am getting failure with error message to start the Appium server programmatically. It is not the case when I start the Appium server on the terminal, but only during running the test in the IDE.

Code To Reproduce Issue [ Good To Have ]

    AppiumDriverLocalService server = GetAppiumService();

... ...

   public AppiumDriverLocalService GetAppiumService() {
        GlobalParams params = new GlobalParams();
        return AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                .usingAnyFreePort()
                .withArgument(() -> "--base-path", "/wd/hub")
                .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                .withLogFile(new File(params.getPlatformName() + "_"
                        + params.getDeviceName() + File.separator + "Server.log")));
    }

Exception Stacktraces

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, 44637, --address, 0.0.0.0, --log, /Users/venkatanutalapati/dev/IntelliJWorkspace/zimperiumzips/iOS_iPhone/Server.log, --base-path, /wd/hub/, --session-override]

Link To Appium Logs

mykola-mokhnach commented 1 year ago

Perhaps the server needs to more time to start on your local machine. Try to increase the default timeout.

vnuta9 commented 1 year ago

@mykola-mokhnach Appreciate your reply. I tried googling but no use, about passing a parameter with value or some thing similar to UiAutomator2Options/XCUITestOptions, so that Appium server takes enough time to start with out throwing that error message. I am losing time with the error anyways. Would you please suggest a means to increase the default time out for starting the Appium Server ?

mykola-mokhnach commented 1 year ago

https://github.com/appium/java-client/blob/8ebb5c320a1b98fbc14ac2f2c9cec1447db76c34/src/test/java/io/appium/java_client/ios/BaseIOSTest.java#L47 could be used as an example

vnuta9 commented 1 year ago

@mykola-mokhnach Great !! It is working now with out throwing an error, so far.

BTW, I installed the following drivers, for my test automation of a Flutter app on both Android and iOS platforms ✔ Listing available drivers

I observed that every time, I start the Server, these drivers are being loaded, out of which I believe only some are required, the rest could be uninstalled to save time. I believe, I can uninstall 'safari', 'gecko', 'mac2' and even 'flutter'. Would you agree ?

Also, in order to use 'gestures' in my tests, like swiping, should I install 'gesture' plugin ?

mykola-mokhnach commented 1 year ago

it is completely up to you what drivers to select. I assume if you only need to automate flutter apps then only the "flutter" driver must be present