@Hassan_Radi I am able to start the appium server below is my code and it's output.
public class AppiumServer {
public void startServer(){
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("D:/Appium/node.exe");
command.addArgument("D:/Appium/node_modules/appium/bin/appium.js");
command.addArgument("--address");
command.addArgument("127.0.0.1");
command.addArgument("--port");
command.addArgument("4724");
command.addArgument("--no-reset");
command.addArgument("--log");
command.addArgument("D:/appiumLogs.txt");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
} catch (IOException e) {
e.printStackTrace();
}
}
public void stopServer(){
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("taskkill");
command.addArgument("/F");
command.addArgument("/IM");
command.addArgument("node.exe");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AppiumServer server=new AppiumServer();
System.out.println("---- Starting appium server ----");
server.startServer();
System.out.println("---- Appium server started Successfully ! ----");
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("---- Stoping appium server ----");
server.stopServer();
System.out.println("---- Appium server stopped Successfully ! ----");
}
}
Output:
---- Starting appium server ----
---- Appium server started Successfully ! ----
---- Stoping appium server ----
---- Appium server stopped Successfully ! ----
SUCCESS: The process "node.exe" with PID 6752 has been terminated.
But when i am trying to set capabilities, i am getting error as session can't be created. Below is the code for capablities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "ANDROID");
capabilities.setCapability("deviceName", "QO4301C12715");
capabilities.setCapability("autoWebview", "true");
capabilities.setCapability("appPackage", "com.android.settings");
capabilities.setCapability("appActivity", "com.android.calendar.LaunchActivity");
capabilities.setCapability("newCommandTimeout", "180");
capabilities.setCapability("autoWebviewTimeout", "6000");
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),
capabilities);
System.out.println("App Launched sucessfully:::");
Please help me out to resolve this issue.