Can't handle multiple @Test

Hi,

I would like to understand how I can handle different @Test in a same Appium test class.
I mean at the moment, after each @Test, @After is triggered, so @Before is then called before the next @Test and so my my driver object is always re instantiate before my second @Test starts.

Here my code:

public class BasicTest {

AndroidDriver driver;

@Before
public void setup() throws MalformedURLException {
    File appDir = new File(directory);
    File app = new File(appDir, apk);
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.0");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("deviceName", "192.168.56.101:5555");
    capabilities.setCapability("appPackage", "package");
    capabilities.setCapability("app", app.getAbsolutePath());
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
@After
public void tearDown() throws Exception {
    driver.quit();
}
@Test
public void connection() throws Exception {
    driver.findElement(...).click();
    driver.findElement(...).sendKeys("...");
    driver.findElement(...).click();
    driver.findElement(...).sendKeys("...");
    driver.findElement(...).click();
}
@Test
public void availability() throws Exception {
    driver.findElement(...).click();
    driver.findElement(...).click();
    driver.findElement(...).click();
}

}

How can I avoid to go back each time into @After & @Before at the end of a @Test ? How can I chain multiple @Test in a same class ?

Thank you.

Use the @BeforeClass and @AfterClass annotation.

1 Like

Thank you James_Kim for that, I didn’t know. It worked and fix my problem, however I have to put @BeforeClass and @AfterClass static to be abel to run my test.