【发布时间】:2017-07-23 14:13:01
【问题描述】:
我正在尝试运行两个功能文件(Cucumber + JUnit),我需要在功能之间关闭浏览器。但关闭后,第二个功能无法启动新会话,我得到了
org.openqa.selenium.remote.SessionNotFoundException: 会话 ID 是 空。
在调用 quit() 后使用 WebDriver。如何避免此错误?
我有以下相同的代码:
@Before
public void initPage(){
loginPage = PageObjectFactory.getPageObject(LoginPage.class);
loginPage.loadPage();
}
@Given("^user login to stg \"([^\"]*)\" with \"([^\"]*)\" and \"([^\"]*)\"$")
public void userLoginToStgWithAnd(String arg0, String arg1, String arg2) throws Throwable {
Properties prop = new Properties();
InputStream input = null;
input = new FileInputStream("src/main/resources/application.properties");
prop.load(input);
arg0 = System.getProperty("url");
arg1 = prop.getProperty("user.username");
arg2 = System.getProperty("user.password");
Map<IElement, String> map = new LinkedHashMap<>();
map.put(loginPage.stgPassword, arg2);
map.put(loginPage.stgUsername, arg1);
driver = WebDriverConfig.setChromeProfile();
driver.get(arg0);
Thread.sleep(3000);
loginPage.waitForJStoLoad();
loginPage.fillForm(map);
loginPage.clickStgLogin();
Thread.sleep(3000);
}
@And("^user logout$")
public void userLogout() throws Throwable {
loginPage.waitForJStoLoad();
loginPage.waitForAngular();
loginPage.openUserProfile();
loginPage.clickLogout();
loginPage.waitForJStoLoad();
driver.close();
}
【问题讨论】: