Start & Stop Appium Server Programmatically using Java (MAC OSX)

Appium is widely used for mobile automation these days. You have to have your Appium server up and running before you can run your automated Appium tests. Most of the times, the test engineers ensure that the Appium server is running before they start executing the test suite. But this arrangement won’t work if you want to run your Appium tests in Continuous Integration/Deployment.

In this post, we will see how to start & stop Appium server programmatically using Java. This code is for Mac OSX (10.10). In next article we will see how to start & stop Appium server programmatically using Java on windows.

So here is the code Create a class called AppiumServer and paste the code mentioned below

In your test class, before you set driver capabilities, start the Appium server like the following

Appiumserver server=new Appiumserver(); 
System.out.println(“—- Starting Appium server —-“); 
server.startServer(); 
//Code for setting desired capabilities goes here (after the server starts successfully) 

Hope you found this useful. If you like this post or found it useful, don’t forget to share it. If you face any difficulties in getting this up and running, kindly comment below and we will try our best to respond.

7 thoughts on “Start & Stop Appium Server Programmatically using Java (MAC OSX)

  1. Bills Reply

    Hi Quick Question

    With this method we can start the Appium server. How do we give it the iOS settings for example that you do through the GUI?

    Or can we set the settings in the Appium GUI and it will set them, and then we can just start the server from the java code.

    Thanks

  2. Right QA Reply

    Which settings you are talking about, in particular? What we have done is we have separate class that takes care of server arguments. And we can pass all the arguments that you can pass the GUI. Feel free to reach me in case you need further information or help. Happy to help! 🙂

  3. Srinivas mit Reply

    hi there,

    Thank you for sharing valuable information

    I am a newbie to appium and struggling to launch appium programatically when I tried your code I end up with below error

    module.js:341
    throw err;
    ^

    Error: Cannot find module '/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3

    Am I missing anything? Please help

    thank you

  4. Srinivas mit Reply

    hi there,

    thank you for sharing valuable information.

    Would please help me as I'm newbie to appium and struggling a lot to run the server programatically

    I have used the code but when I run it… got the below error

    module.js:341
    throw err;
    ^

    Error: Cannot find module '/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3

    is there anything you can help me?

    Thank you

  5. Right QA Reply

    Hi Srinivas mit,

    The error clearly mentions that it cannot find the appium.js file on the specified location.

    If you see .. in startServer()
    there is a line that says

    command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js",false);

    Just replace the path to appium.js to where ever you have installed Appium on your machine.

    Kindly let me know if this helps or you need more information.

    With thanks,
    Right QA Team

  6. Bug Buster Reply

    Hi,

    When I tried the code in appium latest version (1.5.3 – Ara) I am getting the following in the console

    Appium server started.

    0 Scenarios
    0 Steps
    0m0.000s

    Could you please help me to solve this?

Leave a Reply

Your email address will not be published. Required fields are marked *