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.

Comments

  1. 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

    ReplyDelete
    Replies
    1. 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! :)

      Delete
  2. Thanks for this code .. was really helpful and success

    ReplyDelete
  3. 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

    ReplyDelete
  4. 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

    ReplyDelete
    Replies
    1. 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

      Delete

Post a Comment

Popular posts from this blog

Writing first Android test using Appium

Sending keyboard input via ADB to your android device