Launching and stopping appium server programmtically

[Update] For a complete updated guide with code example, please refer to this.

@karthik_holla
I am gonna use Java and Windows to help explain that to you, you can use the equivalent of that in your preferred language/OS:

  • To start Appium server programmatically, you need the following:
    1. Command executor tool (I prefer the second approach as it will handle most of the OS specific problems on your behalf):
    1. Tell the tool what program you need to start. This is OS dependent and differs from OS version to another in some cases. You can use the next table to find the one matching your environment.
    • Windows: cmd /c
    • Linux: /bin/env
    • Mac: /bin/sh
    1. Invoke the NodeJS server and pass the arguments it needs to start the server. You can do that using the following command (Replace C:/Program Files (x86) with the path to your Appium installation folder):

“C:/Program Files (x86)/Appium/node.exe” “C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js”

  1. The last step is to provide the Appium server arguments as normal.

Putting all that together, you formulate a command like:

cmd /c “C:/Program Files (x86)/Appium/node.exe” “C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js” --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone

To execute that command using Apache Commons Exec:

DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
Executor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(new CommandLine(“The command you just formulated above”), resultHandler);

I am not sure if it’s the best approach, but it works just fine with me. @bootstraponline @jlipps Can you please confirm if this is the best approach?


  • To stop Appium server, just replace step 3 above by:

    • Windows: taskkill /F /IM node.exe
    • Linux: killall node
    • Mac: killall node

Note: In case of starting more than one server instance on the same machine, you have to replace the killall command to prevent killing the server of the first instance after staring a second one. Sadly I hit a dead-end in this part (I am currently leaving the server instances opened and I close them manually after the test is done until I find a better approach to killing the server in a more smart way).


  • To capture all Appium log messages in a file, add the following flag to your Appium server arguments:

–log “log-file-path”

Hope this helps. Just ask if anything is not clear :smile:

7 Likes