Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppiumServiceBuilder return appiumJS is null #2007

Closed
AleksandraZelik opened this issue Sep 7, 2023 · 7 comments
Closed

AppiumServiceBuilder return appiumJS is null #2007

AleksandraZelik opened this issue Sep 7, 2023 · 7 comments

Comments

@AleksandraZelik
Copy link

AleksandraZelik commented Sep 7, 2023

Description

Hey folks. I have an issue with starting appium server through the IDE. In some reason, it was worked on Monday, but now not.
I didn't update java, Appium, Selenium, and other things that can have some dependence on it.
I tried to debug it and found that in the AppiumServiceBuilder appiumJS variable is null, even when I override it through withAppiumJS. In the withAppiumJS appium got correct file, but on the builder part I see null exception.

image

Here are my properties:

<properties>
    <java.version>15</java.version>
    <junit.jupiter.version>5.9.0</junit.jupiter.version>
    <junit.platform.version>1.9.0</junit.platform.version>
    <rest-assured.version>5.2.0</rest-assured.version>
    <allure.version>2.19.0</allure.version>
    <maven-surefire.version>2.22.2</maven-surefire.version>
    <aspectj.version>1.9.6</aspectj.version>
    <maven-compiler.version>3.10.1</maven-compiler.version>
    <allure-maven.version>2.10.0</allure-maven.version>
    <gson.version>2.9.0</gson.version>
    <lombok.version>1.18.24</lombok.version>
    <selenium.version>4.9.1</selenium.version>
    <appium.version>8.5.0</appium.version>
    <postgresql.vervion>42.4.1</postgresql.vervion>
    <hibernate.version>5.6.9.Final</hibernate.version>
    <parallelTests>1</parallelTests>
</properties>

Laptop details:

OS: macOS Ventura 1.13
Java: 15.0.2
appium: 2.1.3
node: 18.17.1

Code To Reproduce Issue:

package base;

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.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import utils.ReadProperties;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;

import static io.appium.java_client.service.local.flags.GeneralServerFlag.SESSION_OVERRIDE;
import static java.lang.String.format;
import static utils.Constants.KILL_NODE_COMMAND;

public class AppiumStarter {
private static AppiumDriverLocalService appiumDriver;
private static final Logger logger = LogManager.getLogger(AppiumStarter.class);

public static AppiumDriverLocalService getAppiumDriver(int port) {
    if (appiumDriver == null) startService(port);

    return appiumDriver;
}

public static void startService(int port){
   makePortAvailableIfOccupied(port);
    appiumDriver = new AppiumServiceBuilder()
            .withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
            .withIPAddress(ReadProperties.getAppiumAddress())
            .usingPort(ReadProperties.getAppiumPort())
            .usingDriverExecutable(new File("/usr/local/bin/node"))
            .withArgument(GeneralServerFlag.BASEPATH, ReadProperties.getAppiumBasePath())
            .withArgument(SESSION_OVERRIDE)
            .build();
    logger.info("Create Appium Server with next settings: AppiumAddress {}, Port {}, BasePath {}, Argument {}", ReadProperties.getAppiumAddress(), ReadProperties.getAppiumPort(), ReadProperties.getAppiumBasePath(), SESSION_OVERRIDE);
    appiumDriver.start();
    logger.info("Start Appium Server");
}

public static void closeAppium() {
    appiumDriver.stop();
}


private static void makePortAvailableIfOccupied(int port) {
    if (!isPortFree(port)) {
        try {
            logger.info("If port {} not free, we kill this process", port);
            Runtime.getRuntime().exec(KILL_NODE_COMMAND);
        } catch (IOException e) {
            logger.debug(e.getStackTrace());
        }
    }
}

private static boolean isPortFree(int port) {

    boolean isFree = true;
    try (ServerSocket ignored = new ServerSocket(port)) {
        logger.info("Checking, that port {} is free", port);
    } catch (Exception e) {
        isFree = false;
        logger.debug(e.getStackTrace());
    }
    return isFree;
}

public static void closeEmulator() {
    logger.info("Close Emulator {} after tests", ReadProperties.getAndroidUdid());
    try {
        Runtime.getRuntime().exec(format("adb -s %s emu kill", ReadProperties.getAndroidUdid()));
    } catch (IOException e) {
        logger.debug(e.getStackTrace());
    }
}

}

@mykola-mokhnach
Copy link
Contributor

Maybe a duplicate of #2004

Try to downgrade the selenium version as a workaround

@AleksandraZelik
Copy link
Author

@mykola-mokhnach, i'm not sure that the issue is the same. And unfortunately downgrading the selenium version didn't help.

@mykola-mokhnach
Copy link
Contributor

@mykola-mokhnach, i'm not sure that the issue is the same. And unfortunately downgrading the selenium version didn't help.

The stack trace looks similarly. Have you also tried to provide the log output explicitly?

@AleksandraZelik
Copy link
Author

@mykola-mokhnach thank you, added withLogOutput(ByteStreams.nullOutputStream()). And it is work

@valfirst
Copy link
Collaborator

valfirst commented Sep 9, 2023

Duplicate of #2004

@valfirst valfirst marked this as a duplicate of #2004 Sep 9, 2023
@valfirst valfirst closed this as completed Sep 9, 2023
@madhura-75
Copy link

Hi, What is the solution for the above issue?

@madhura-75
Copy link

@AleksandraZelik Did you find solution for above issue? Even I am facing same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants