Java – session ID is empty. Use WebDriver after calling quit().

session ID is empty. Use WebDriver after calling quit()…. here is a solution to the problem.

session ID is empty. Use WebDriver after calling quit().

I’m trying to add a new contact by reading test data from an excel file. The first row of data is created. After the second line, I get the error message “org.openqa.selenium.NoSuchSessionException: Session ID is empty.” Use WebDriver after calling quit(). ”

I rechecked my code and found that the other test cases worked fine.
I follow the process below
Go to Base URL – > Sign In – > Add Contact – >driver.quit().

@AfterMethod
    public void teardown() {

driver.quit();
    }

I want to read the data and add multiple contacts

Solution

You use @AfterMethod here and @AfterMethod execute after each execution of the method, in your case, after one iteration of excel, it is executed and the driver instance ends because you used driver.quit() here.

Therefore, to solve this problem, you should use @AfterTest instead of @AfterMethod, because @AfterTest your test case execution is complete only if all rows from excel get executed.

Related Problems and Solutions