Start-Stop Appium Server Programmatically - Method 1

Start as well as halt appium server Programmatically means start the appium server using code when your software app attempt execution started as well as stop appium server using code when software app  test execution finished. Till now, We convey learnt how to start appium server manually from commencement card In THIS POST, as well as using ascendancy prompt equally described In THIS POST. Now permit me explicate you how to commencement as well as halt appium server Programmatically. HERE Is unopen to other way of starting appium server programatically.

App To Use In This Test
We volition use Api Demos app In this attempt to demonstrate y'all how to commencement appium server programmatically. Earlier nosotros convey used same software app In many appium android software attempt examples.

Aim To Achieve
Earlier nosotros were starting appium server manually earlier running attempt as well as stopping It manually on android app software attempt execution completion. Now nosotros wants to commencement as well as halt It programmatically. So nosotros volition write unopen to logic In our attempt instance file to commencement as well as halt appium server.

Create And Run Android App Software Test
Create new AppiumStartAndStop.java degree file nether Android bundle of your projection as well as glue bellow given attempt In It.

Note 1 : In bellow given attempt script, If your node.exe Is located at whatsoever other path hence y'all need modify value of nodePath string. Generally It volition hold out located at C:\Program Files\Appium.


Note two : Same affair applied for appium.js file. Change value of appiumJSPath string If It Is dissimilar for you.


AppiumStartAndStop.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.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 degree AppiumStartAndStop {  Process p;  // Set path of your node.exe file.  // Progra ,1 represents Program Files folder.  String nodePath = "C:/Progra ,1/Appium/node.exe";  // Set path of your appium.js file.  String appiumJSPath = "C:/Progra ,1/Appium/node_modules/appium/bin/appium.js";  String cmd = nodePath + " " + appiumJSPath;  AndroidDriver driver;   // This method Is responsible for starting appium server.  populace void appiumStart() throws IOException, InterruptedException {   // Execute ascendancy string to commencement appium server.   p = Runtime.getRuntime().exec(cmd);   // Provide expression fourth dimension of ten mins to commencement appium server properly.   // If human face upward whatsoever error(Could non commencement a novel session...) hence Increase   // this fourth dimension to fifteen or twenty mins.   Thread.sleep(10000);   if (p != null) {    System.out.println("Appium server Is started now.");   }  }   // This method Is responsible for stopping appium server.  populace void appiumStop() throws IOException {   if (p != null) {    p.destroy();   }   System.out.println("Appium server Is stopped now.");  }   @BeforeTest  populace void setUp() throws Exception {   // Stop appium server If It Is already running.   appiumStop();   // 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 ScrollToView() {   // Scroll till chemical part 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 attempt Is ended.   appiumStop();  } }

Test Script Description
In higher upward test, appiumStart() method Is responsible to commencement appium server and appiumStop() method to halt appium server. We convey telephone phone appiumStart() method In @BeforeTest annotated method to commencement appium server earlier attempt starts as well as call appiumStop() method In @AfterTest annotated method to halt appium server afterwards attempt execution.

Don't commencement appium server manually as well as move higher upward android app software attempt using testng. It volition commencement appium server In background as well as move attempt In android device.

Next postal service volition demo y'all unopen to other method of starting as well as stopping 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