Monday 4 June 2018

Easiest Way to Start Appium Server with Java Code

When we are building an automation framework it is very important to perform end to end automation including starting and stopping appium server. keeping that in mind in this post I will be sharing simplest and quickest way to install appium server and start & stop appium server using simple java code.
This is very simple and easy way to start appium server programmatically using java code. In our previous tutorial we have seen how to start appium server using java code with this   AppiumDriverLocalService class. But in this tutorial we will see very simple and quick way of installing appium server and starting it using simple java code.


Step 1 > Install Node Js from  HERE
 
Step 2 > Open Node Js Command Prompt as shown below.

Step 3 > Execute command npm install -g appium
 
Step 4 > Verify Appium is Installed Successfully by executing command  appium -v
 
Step 5 > Start appium server using command appium -a 127.0.0.1 -p 4723
 
Step 6 > Do CTRL + C to stop ther server

Below is the Java Code to Start and Stop Appium Server Programaticall. In the code we
are executing the command using java to start and stop the server.
Do try this out and post your feedback, Suggestion and questions in comment section 
below.



import java.io.IOException;

/**
 * Appium Manager - this class contains method to start and stops appium server  
 */
public class AppiumManager {

 public void startServer() {
  Runtime runtime = Runtime.getRuntime();
  try {
   runtime.exec("cmd.exe /c start cmd.exe /k \"appium -a 127.0.0.1 -p 4725 --session-override -dc \"{\"\"noReset\"\": \"\"false\"\"}\"\"");
   Thread.sleep(10000);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 public void stopServer() {
  Runtime runtime = Runtime.getRuntime();
  try {
   runtime.exec("taskkill /F /IM node.exe");
   runtime.exec("taskkill /F /IM cmd.exe");
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

1 comment:

  1. Notable points on your website. We are interested to add some more information to this post. Keep posting new content.
    Thanks
    Reliable dedicated hosting

    ReplyDelete