首页 > 解决方案 > Selenium webdriver 版本不正确时不会退出

问题描述

我正在为学校开发一个测试自动化框架。一切都很好,除非我为不同版本的浏览器设置驱动程序。我无法退出它。

铁。我有 Chrome 83,我尝试使用 Chrome 84 的驱动程序运行我的测试。Java 给出以下错误:

org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 84

我知道您不允许使用不同版本的 Chromedrivers 和不同的 Chrome,但是如果有人这样做并想在之后更换驱动程序怎么办?

显然,当加载了不正确的版本时, driver = null 。我无法在代码中退出它,它一直在后台运行。因此无法更换或删除项目中的驱动程序。我只想找到一种方法,以在抛出“SessionNotCreatedException”时以编程方式退出驱动程序,而不是在任务管理器中强制退出它。

@BeforeEach
public void beforeSuite() throws MalformedURLException, IOException {           

    String browser = configProperties.getProperty("browser");

    switch(browser.toLowerCase()) {
        case "chrome":
            System.setProperty("webdriver.chrome.driver", configProperties.getProperty("chromepath"));
            driver = new ChromeDriver();
            break;
}

@AfterEach
public void afterSuite() {
    driver.quit();
}

标签: seleniumselenium-webdriverjunitselenium-chromedriverjunit5

解决方案


推荐阅读