Appium server not running in CI

The appium server (2.5.1) starts (image), but stops with error 500 because it says it cannot find UiAutomator2. This is supposed to be checked by the server at startup and if not installed. For CI this is logical.


AppiumServiceBuilder:

public static void appiumStart(DesiredCapabilities caps){
        try {
            AppiumServiceBuilder builder = new AppiumServiceBuilder();
            service = AppiumDriverLocalService.buildService(builder);
            builder
                    .withIPAddress("127.0.0.1")
                    .usingPort(AppiumServiceBuilder.DEFAULT_APPIUM_PORT)
                    .withArgument(BASEPATH, "/wd/hub")
                    .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                    .withArgument(GeneralServerFlag.LOG_LEVEL, "info")
                    .withCapabilities(caps)
                    .build();

            service.start();
            Sleep.forMillis(10000);
        }catch (SessionNotCreatedException e){}
    }

Capabilities:

private static AndroidDriver startApp(boolean noReset) {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("platformName", PropertyReader.getInstance().appiumPlatformname());
        caps.setCapability("platformVersion", PropertyReader.getInstance().appiumPlatformVersion());
        caps.setCapability("udid", PropertyReader.getInstance().appiumUdid());
        caps.setCapability("automationName", PropertyReader.getInstance().appiumAutomationName());
        caps.setCapability("app", PropertyReader.getInstance().appiumApp());
        caps.setCapability("appWaitPackage", PropertyReader.getInstance().appiumAppPackage());
        caps.setCapability("appWaitActivity", PropertyReader.getInstance().appiumAppActivity());
        caps.setCapability("noReset", noReset);
        appiumStart(caps);
        try {
            AndroidDriver appDriver = new AndroidDriver(service.getUrl(), caps);
            return appDriver;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

What is the solution? Thanks in advance for your reply.

In many cases while your code executing on remote machine it does not have environment.

e.g. execute in terminal on your machine

echo $PATH

and compare output with same command executed in CI.
In many cases output will be different and you will see absence of many paths.

To fix this e.g. with Jenkins you can set correct path to whole machine or use Inject environment variables to the build process in job configuration.

1 Like

Hello Aleksei,

thanks for your answer!
The test runs when I start the appium server as a separate application, so I think the capabilieties are good.
The above data have not changed, so I will not reattach them.
If I start the appium server at the beginning of the test, it throws this error:

java.lang.RuntimeException: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 

since I am using version 2.5.1, I tried to use the “http://127.0.0.1:4723/”, but it wouldn’t start, so I reverted to the “http://127.0.0.1:4723/wd/hub

According to the descriptions, this is how it should work. What am I missing?