For each @Test method my script runs it individually (restarts my android app)


My test uses selenium / junit but when i run it it re- starts my android app for each test method and runs it individually…

Heres my code so far:

import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;


public class ProductionAppTest {

AndroidDriver driver;
Dimension size;
String destDir;
DateFormat dateFormat;

public void setUp() throws MalformedURLException {

    // Created object of DesiredCapabilities class.
    DesiredCapabilities capabilities = new DesiredCapabilities();

    // Set android deviceName desired capability. Set your device name.
    capabilities.setCapability("deviceName", "HT35HW914408");

    // Set BROWSER_NAME desired capability. It's Android in our case here.
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

    // Set android VERSION desired capability. Set your mobile device's OS version.
    capabilities.setCapability(CapabilityType.VERSION, "5.0.2");

    // Set android platformName desired capability. It's Android in our case here.
    capabilities.setCapability("platformName", "Android");

    // Dont reset the app for the session
    capabilities.setCapability("fullReset", "false");
    capabilities.setCapability("noReset", "true");

    // Set android appPackage desired capability.
    // Set your application's appPackage
    capabilities.setCapability("appPackage", "");

    // Set android appActivity desired capability.
    // Set your application's appActivity.
    capabilities.setCapability("appActivity", "");

    // Created object of RemoteWebDriver will all set capabilities.
    // Set appium server address and port number in URL string.
    // It will launch xxxx app in android device.
    driver = new AndroidDriver(new URL("http://xxx:xxx/wd/hub"), capabilities);

    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


public void aLoginscreens() throws InterruptedException {

    WebDriverWait wait = new WebDriverWait(driver, 10);
    //This test will focus on doing a regular login using an email
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    //take screenshot of the login screen
    WebElement loginButton = driver.findElement(By.xpath("//android.widget.Button[@text='LOGIN' and @index='0']"));

    //Get the size of screen.
    size = driver.manage().window().getSize();
    //Find swipe start and end point from screen's with and height.
    //Find startx point which is at right side of screen.
    int startx = (int) (size.width * 0.70);
    //Find endx point which is at left side of screen.
    int endx = (int) (size.width * 0.30);
    //Find vertical point where you want to swipe. It is in middle of screen height.
    int starty = size.height / 2;
    System.out.println("startx = " + startx + " ,endx = " + endx + " , starty = " + starty);

    //Swipe from Left to Right.

    driver.swipe(startx, starty, endx, starty, 1000);


public void bLoginWithEmail(){
    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement loginButton = driver.findElement(By.xpath("//android.widget.Button[@text='LOGIN' and @index='0']"));

public void bLoginWithEmail(){

     Click on login  button.
    driver.findElement(By.xpath("//android.widget.Button[@text='LOGIN' and @index='0']")).click();
    login using jaylennes email
    enter email
    driver.findElement(By.xpath("//android.widget.EditText[@text='Email / Username' and @index='1']")).sendKeys("[email protected]");
    enter password
    driver.findElement(By.xpath("//android.widget.EditText[@NAF='true' and @index='1']")).sendKeys("xxx");


public void takeScreenShot() {
    // Set folder name to store screenshots.
    destDir = "screenshots";
    // Capture screenshot.
    File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    // Set date format to set It as screenshot file name.
    dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
    // Create folder under project with name "screenshots" provided to destDir.
    new File(destDir).mkdirs();
    // Set file name using current date time.
    String destFile = dateFormat.format(new Date()) + ".png";

    try {
        // Copy paste file at destination folder location
        FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
    } catch (IOException e) {


public void End() {



Not really an Appium problem. The problem is that you don’t understand TestNg annotations. You are looking for @BeforeSuite or something similar. Read up more here:

Or if you are using jUnit, just add an…

public void setUp() throws MalformedURLException {

    if (driver == null) {

      <all your driver init code here>



That way, it will only do it once.

thanks!! solved my problem! had to edit some annotations.