I am using QAF open source Java library in my UI Automation Framework and wanted to open and close the browser with each test. But, can't do it with below code hence browser which is opened by testSuccessfulLogin() keeps opened hence the testFailedLogin() fails.
public class LoginTestCase extends WebDriverTestCase {
@Test(testName="SuccessfulLogin", description="Successful Login with valid username and password", groups={"SMOKE"})
public void testSuccessfulLogin() {
LoginPage loginPage = new LoginPage();
loginPage.openPage();
verifyLinkWithTextPresent("Or Sign Up");
loginPage.enterUsername("asdf.asdf");
loginPage.enterPassword("Asdf@1234");
loginPage.clickLogInButton();
verifyLinkWithTextPresent("Dashboard");
verifyLinkWithTextPresent("Logout");
}
@Test(testName="FailedLogin", description="Login with blank username and password", groups={"SMOKE"})
public void testFailedLogin() {
LoginPage loginPage = new LoginPage();
loginPage.openPage();
verifyLinkWithTextPresent("Or Sign Up");
loginPage.enterUsername("");
loginPage.enterPassword("");
loginPage.submitLoginForm();
verifyLinkWithTextPresent("Dashboard");
verifyLinkWithTextPresent("Logout");
}
}
You can achieve it by setting selenium.singletone=method
. Specify it in application properties or in xml configuration file. Refer list of properties and how to set properties.