I'm using Selenium using both Java and Cucumber. And I'm curious when I'm using driver.quit()
or driver.close()
under @AfterTest
method, browser won't closed and when I'm using it inside my test step i.e @Test
annotated method. It's called perfectly within steps.
Refer below code for the same :
@Then("^I see Dashboard$")
public void iSeeDashboard() throws Throwable {
LoginPage lp = new LoginPage(driver);
Assert.assertEquals(lp.TitleId().getText(),"Mengelola User Customer");
log.info("Successfully Login");
driver.quit();
}
And here the whole code and I want to put driver.quit
under @AfterTest
public class LoginStep extends steps.BaseStep {
public static Logger log =
LogManager.getLogger(steps.BaseStep.class.getName());
@BeforeTest
public void before() throws IOException
{
driver = initializeDriver();
log.info("Driver is Initialized");
}
@Given("^I navigate to Website$")
public void iNavigateToWebsite() throws IOException {
driver = initializeDriver();
driver.get(prop.getProperty("URL"));
log.info("Navigate to Website");
}
@Then("^I enter username and password")
public void iEnterUsernameAndPassword() throws IOException {
LoginPage lp = new LoginPage(driver);
lp.UsernameId().sendKeys("xxx");
lp.PasswordId().sendKeys("xxx");
log.info("Successfully entered valid credentials");
}
@When("^I click Login$")
public void iClickLogin() throws Throwable {
LoginPage lp = new LoginPage(driver);
lp.LoginId().click();
}
@Then("^I see Dashboard$")
public void iSeeDashboard() throws Throwable {
LoginPage lp = new LoginPage(driver);
Assert.assertEquals(lp.TitleId().getText(),"Lorem ipsum");
log.info("Successfully Login");
//driver.quit();
}
@AfterTest
public void tearDown()
{
driver.quit();
}
Any explanation would be helpful.