selenium - 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();
}
解决方案
推荐阅读
- python - 使用 glob2 将两个文本文件合并到一个文件中
- javascript - Getter 在 JS 中返回未定义,即使它在第一次调用中工作
- angularjs - 如何让多行工具提示与 AngularJS 一起工作?
- python - Gunicorn 自行运行,但不在 docker 容器中运行
- laravel - 如何在共享虚拟主机中部署 laravel 项目?
- javascript - 如何在 Firefox for Android 上为视频创建缩略图
- node.js - 为什么我的 Mongoose 模型在传递集合名称后仍返回空白响应?
- c++ - C++ Linked List Implementation accessing data
- html - Postion: absolute;
- html - Font awesome icon is moving outside of its parent container with position:absolute