The only possible way I can think is using TestNG priority
, groups
and dependsOnGroups
properties.
You'll have to run the full
group for this works and you'll need to have at least two test on the LoginTest.
Without the second test, LoginTest will close after the validateLogin
finish and validateSession
will fail.
The code below will follow the execution:
- Will start LoginTest and SessionTest suites
- Test "validateLogin" and "validateSession" will start first since it has priority = 1
- But "validateSession" will wait "validateLogin" because it dependsOnGroups = "smoke"
- When "validateLogin" finish, "validateSession" will start
- Test "validateLoginStuff2" will wait "validateSession" because it dependsOnGroups = "session"
- When "validateSession" finish "validateLoginStuff2" will start and the session validation will be done.
public class LoginTest{
WebDriver driver;
@beforeClass
protected void beforeClass() {driver = new FirefoxDriver();
driver.get("www.url.com");
}
@Override
protected void afterClass() {
driver.quit();
}
@Test(priority = 1, groups = {"smoke", "full"})
public void validateLogin() {
//do login stufs
}
@Test(priority = 2, groups = {"full"}, dependsOnGroups = "session")
public void validateLoginStuff2() {
//do login stuff2 validation
}
}
public class SessionTest{
WebDriver driver;
@beforeClass
protected void beforeClass() {
driver = new FirefoxDriver();
}
@Override
protected void afterClass() {
driver.quit();
}
@Test(priority = 1, groups = {"session", "full"}, dependsOnGroups = "smoke")
public void validateSession() {
//do validate session things
}
}