我使用的是Selenium+Cucumber+TestNG,我试图在我的功能之间关闭和打开一个新的浏览器。这是我的要求,因为我的应用程序中没有注销功能。下面是我的代码。
@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
以下是“我”“关闭”浏览器以作为另一名分析师登录“的步骤定义。
@Then("I {string} the browser for logging in as another analyst")
public void closeTheSessionForLoggingInAsOtherAnalyst(String mode) {
researchTicketDashboardPage.clearBrowserStorage(mode);
}
在clearBrowserStorage方法中,我尝试关闭浏览器并再次打开它。
driver.close();
Base.initializeBrowserSetup();
我收到以下错误。
When User launch the "MISToolkit" application on browser # stepDefinitions.LoginPageStepDefinitions.userLaunchTheApplicationOnBrowser(java.lang.String)
org.openqa.selenium.NoSuchSessionException: invalid session id
我错过什么了吗?
1条答案
按热度按时间ycl3bljg1#
driver.close()如果只有一个浏览器打开https://www.browserstack.com/guide/close-browser-in-selenium则终止会话
您需要在关闭原始驱动程序后创建一个新会话。