\node\bin\node is appending at the end of path when run appium programatically


#1

I am using appium support library to run the appium. But somehow when it goes to find the appium directory it appends \node\bib\node at the end of file path rather then at start. I am using mac.My code is:

private static String APPIUMSERVERSTART= "/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js ";

public void startServer() throws IOException, InterruptedException {
ServerArguments serverArguments = new ServerArguments();

serverArguments.setArgument("--address", "127.0.0.1");
serverArguments.setArgument("--chromedriver-port", 9516);
serverArguments.setArgument("---port", 4723);
serverArguments.setArgument("--no-reset", true);
serverArguments.setArgument("--local-timezone", true);
serverArguments.setArgument("--platform-name", "ANDROID");

serverArguments.setArgument("–platform-version", “5.1.1”);
serverArguments.setArgument("–app-pkg", “com.android.settings”);
serverArguments.setArgument("–app-activity", “com.android.calendar.LaunchActivity”);
AppiumServer appiumServer = new AppiumServer(new File(APPIUMSERVERSTART),
serverArguments);

appiumServer.startServer();
System.out.println(appiumServer.isServerRunning());
System.out.println("Appium server started");

Thread.sleep(5000);

}
The failure error i get is :

com.github.genium_framework.server.exception.InvalidNodeFilePathException: The file you provided was not found on your HDD. You provided the following file path:/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js /node/bin/node

Can anybody point me towards right direction and tell what i am doing wrong ?Any help would be appreciated. Thanks.


#2

When we start our server, we do so with "node ". e.g. if your node modules directory is in the current directory, this would be “node node_modules/appium”. You have “node_modules/appium/bin/appium.js”


#3

Here’s a good tutorial for starting server from any OS:


#4

I am able to run the appium successfully through code but on capabilities when it tries to connect to localhost IP Address it fails. if i start appium manually through terminal and then run the code it works perfectly. i have looked into many tutorial but coudnt get any success. Tried all the different ports too.

Here is the code:
CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js", false);
command.addArgument("–address", false);
command.addArgument(“127.0.0.1”);
command.addArgument("–port", false);
command.addArgument(“4723”);
command.addArgument("–bootstrap-port", false);
command.addArgument(“4724”);

//command.addArgument("--full-reset", false);
//command.addArgument("--session-override", true);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
    executor.execute(command, resultHandler);
    Thread.sleep(5000);
    System.out.println("Appium server started.");
} catch (IOException e) {
    e.printStackTrace();

}

For Capabilities:

DesiredCapabilities capabilities = new DesiredCapabilities();

//common capabilities

capabilities.setCapability("appium-version", "1.6.4");
capabilities.setCapability("platformName", "Android");

//capabilities for Emulator
capabilities.setCapability("platformVersion", "7.1.1");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 7");
capabilities.setCapability("app", "/Users/tvs00023/Desktop/KwizzAdd.apk");

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

The error is :
org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused (Connection refused)
Build info: version: ‘3.3.1’, revision: ‘5234b32’, time: ‘2017-03-10 09:04:52 -0800’

caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused (Connection refused)

Can anybody help me out in this ?