How To Start-Stop Appium Server Programmatically - Method 2

Earlier In PREVIOUS POST, I convey described yous ane of the instance to start as well as halt appium server programmatically in your android software app automation testing amongst practical example. Now allow me explicate yous roughly other method to start as well as halt appium server programmatically. You tin purpose whatsoever these 2 methods to start as well as halt appium server In your appium software automation test.

App To Use And Aim To Achieve
We volition purpose same Api Demos android software app In this test. Also our aim Is to showtime as well as halt appium server programatically. In this test, We volition use CommandLine flat of apache to execute commands for starting as well as stopping appium server during software automation evidence execution.

Create And Run Test
Create new AppiumStartStop.java file In Android bundle of your projection In eclipse as well as purpose bellow given evidence script In It.

Note : In bellow given appium software automation evidence script, If your node.exe and appium.js are located at whatsoever other path as well as then delight update values of nodePath and appiumJSPath string variables accordingly.

AppiumStartStop.java
package Android;  import io.appium.java_client.android.AndroidDriver; import java.io.IOException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecuteResultHandler; import org.apache.commons.exec.DefaultExecutor; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace flat AppiumStartStop {  static AndroidDriver driver;  // Set path of your node.exe file. Set your path.  // Progra ,1 represents Program Files folder.  String nodePath = "C:/Progra ,1/Appium/node.exe";  // Set path of your appium.js file. Set your path.  String appiumJSPath = "C:/Progra ,1/Appium/node_modules/appium/bin/appium.js";   // This method Is responsible for starting appium server.  populace void appiumStart() throws IOException, InterruptedException {   // Created object of apache CommandLine class.   // It volition showtime ascendence prompt In background.   CommandLine ascendence = novel CommandLine("cmd");   // Add dissimilar arguments In ascendence trouble which requires to showtime appium server.   command.addArgument("/c");   command.addArgument(nodePath);   command.addArgument(appiumJSPath);   //Set Server address   command.addArgument("--address");   command.addArgument("127.0.0.1");   //Set Port   command.addArgument("--port");   command.addArgument("4723");   command.addArgument("--no-reset");   command.addArgument("--log");   //Set path to shop appium server log file.   command.addArgument("D://appiumLogs.txt");   // Execute ascendence trouble arguments to showtime appium server.   DefaultExecuteResultHandler resultHandler = novel DefaultExecuteResultHandler();   DefaultExecutor executor = novel DefaultExecutor();   executor.setExitValue(1);   executor.execute(command, resultHandler);   // Wait for fifteen minutes thence that appium server tin showtime properly earlier going for evidence execution.   // Increase this fourth dimension If aspect upward whatsoever error.   Thread.sleep(15000);  }   // This method Is responsible for stopping appium server.  populace static void appiumStop() throws IOException {   // Add dissimilar arguments In ascendence trouble which requires to halt appium server.   CommandLine ascendence = novel CommandLine("cmd");   command.addArgument("/c");   command.addArgument("taskkill");   command.addArgument("/F");   command.addArgument("/IM");   command.addArgument("node.exe");   // Execute ascendence trouble arguments to halt appium server.   DefaultExecuteResultHandler resultHandler = novel DefaultExecuteResultHandler();   DefaultExecutor executor = novel DefaultExecutor();   executor.setExitValue(1);   executor.execute(command, resultHandler);  }   @BeforeTest  populace void setUp() throws Exception {   // Start appium server.   appiumStart();   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability("deviceName", "ZX1B32FFXF");   capabilities.setCapability("browserName", "Android");   capabilities.setCapability("platformVersion", "4.4.2");   capabilities.setCapability("platformName", "Android");   capabilities.setCapability("appPackage", "io.appium.android.apis");   capabilities.setCapability("appActivity", "io.appium.android.apis.ApiDemos");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  populace void ScrollToTab() {   // Scroll till chemical cistron which contains "Views" text If It Is non visible on screen.   driver.scrollTo("Views");   // Click on Views.   driver.findElement(By.name("Views")).click();  }   @AfterTest  populace void End() throws IOException {   driver.quit();   // Stop appium server when evidence Is ended.   appiumStop();  } }

Test Script Description
If yous run across In evidence script, I convey created appiumStart() and appiumStop() methods which are responsible to showtime as well as halt appium server during software test script execution. We convey ready few ascendence trouble arguments as well as executed them to showtime as well as halt appium server.

This agency yous tin showtime as well as halt appium server programmatically.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post