Background: I am trying to write end-to-end selenium tests using Fluentlenium (in Java, fwiw)
I could use some help with trying to figure out whether there is a way to extend the life of a webdriver session beyond the scope of @Test
method in TestNG, when extending FluentTestNg
. Right now, I see the browser session just exit after one @Test method completes and a new one pops up at the start of the next @Test
method. I would prefer to be able to use @Test(dependsOnMethods = "previousMethod")
during UI Tests and hence, carry over the browser session to the next method.
I have Test class that extends FluentTestNg
, with a @BeforeClass
(even a @BeforeSuite
) where I initialize the browser based on the value of system property then
call test methods. I have posted the snippet below.
public class LoginTest extends FluentTestNg {
@BeforeClass
public static void setupClass() {
List<String> browserList = Arrays.stream(DriverManagerType.values()).
map(DriverManagerType::toString).collect(Collectors.toList());
String browserName = CaseUtils.toCamelCase(System.getProperty("fluentlenium.webDriver"),true);
if(browserList.contains(browserName)) {
DriverManagerType driverManagerType = DriverManagerType.valueOf(browserName.toUpperCase());
WebDriverManager.getInstance(driverManagerType).setup();
}
}
@Test
public void logIn() {
// something
}
@Test(dependsOnMethods = "logIn")
public void logOut() {
// some more thing to logout
}
}
The documentation does not discuss anything for such situations, hence, falling back on SO. I feel that someone out there might already have an answer or resolution, for this.