I am using Selenium Cucumber TestNG and I am trying to close and open a new browser in between my feature. That is my requirement as there is no logout feature present in my application. Below is my code.
@Regression @Recall
Scenario: Validate workflow with Recall from Closed tab
Given User launch the "MISToolkit" application on browser
When "approver" logs in to application
Then "MISToolKit" page should appear
Then User navigates to "ResearchTicketDashboard" page
Then User navigates to WorkQueue on Research Ticket Dashboard Page
And I "close" the browser for logging in as another analyst
When User launch the "MISToolkit" application on browser
When "analyst" logs in to application
Below is the step definition for And I "close" the browser for logging in as another analyst.
@Then("I {string} the browser for logging in as another analyst")
public void closeTheSessionForLoggingInAsOtherAnalyst(String mode) {
researchTicketDashboardPage.clearBrowserStorage(mode);
}
And inside the clearBrowserStorage method I am trying to close the browser and open it again.
driver.close();
Base.initializeBrowserSetup();
I am getting following error.
When User launch the "MISToolkit" application on browser # stepDefinitions.LoginPageStepDefinitions.userLaunchTheApplicationOnBrowser(java.lang.String)
org.openqa.selenium.NoSuchSessionException: invalid session id
Am I missing something here?
CodePudding user response:
driver.close() kills the session if there is only one browser open https://www.browserstack.com/guide/close-browser-in-selenium
You will need to create a new session after closing the original driver.