The problem
I am trying to run appium server through java code. i am using Mac OS. After running the code appium server starts successfully 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 ?