Start Appium Server Programmatically Using Java

Executing Appium tests for Android and iOS requires Appium server running in background. While you can always start the server manually before running your tests, this may not be a good approach if you are targeting full automation (Eg. while running your tests in CI). Therefore it’s recommended to start Appium server programmatically. This post shows how we can achieve this using Java for Mac and Windows platforms.Start Appium Server Programmatically

Some background:

Appium server is basically a JavaScript server built using NodeJS. So to start it, we’ll need to supply Appium server JavaScript file to NodeJS executable. We also need to pass additional arguments if required.

Armed with this much information, let’s get into the meat of the matter.

Start Appium server programmatically on Mac:

  • Write below shell script and save it in your system. Here we are supplying NodeJS executable (please note here that NodeJS executable is supplied by Appium itself) followed by Appium.js file and additional arguments such as port and address. You might need to modify these as per your requirements.
  • Write below Java code (preferably in your setup method) to execute the shell script we have written. You may want to add some delay for Appium server to start after this code.
  • The above code will start Appium server on address 127.0.0.1 port 4724 as specified in shell script.

Start Appium server programmatically on Windows:

  • The procedure to start Appium server is more or less same as Mac. You’ll have to supply Node executable, Appium server file and additional arguments. But to execute this command, we will need to use Process class of Java.
  • Write below code in your setup method. You’ll need to change Node and Appium executable as per your system.
  • This will start Appium server on default address and port.

The obvious advantage of starting Appium programmatically is reduced manual intervention. This way testers can run their automated tests during off hours, resulting in higher efficiency. Do you know any other way we can start Appium server programmatically? Do share with us in comments.

Comments
  1. kaviyaa
  2. Shanoj Thekkan Ramath
    • VIJAY ANAND
  3. venkatesh
  4. Nagesh

Leave a Reply

Your email address will not be published.