Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Start & Stop Appium Server Programmatically using Java (MAC OSX)
package utilities;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import java.io.IOException;
/**
*
* @author RightQA
*
*/
public class AppiumServer {
public void startServer() {
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("--full-reset", false);
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();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void stopServer() {
String[] command = { "/usr/bin/killall", "-KILL", "node" };
try {
Runtime.getRuntime().exec(command);
System.out.println("Appium server stopped.");
} catch (IOException e) {
e.printStackTrace();
}
}
}

The start and stop methods are good to go with if we have only one instance of appium server. What if we have multiple appium server launched and we want to stop a particular node. using given code to stop server stops all the servers launched.

welcome your suggestions...

I'm also having same question, what we can do if we have 2 appium server instance. @benz-philip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment