gpt4 book ai didi

java - driver.quit后如何打开chromedriver的新 session ?

转载 作者:行者123 更新时间:2023-11-30 06:35:26 24 4
gpt4 key购买 nike

我正在尝试运行两个功能文件(Cucumber + JUnit),并且我需要在功能之间关闭浏览器。但关闭后,第二个功能无法启动新 session ,我得到了

org.openqa.selenium.remote.SessionNotFoundException: Session ID is null.

调用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();
}

最佳答案

你可以这样做:

driver.quit();
driver = null;
driver = new ChromeDriver();

关于java - driver.quit后如何打开chromedriver的新 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com