Serenity为何启动旧版Chromedriver?如何配置使用正确版本?
问题
克隆GitHub上的serenity-cucumber-starter仓库,选择action-classes分支作为起点,执行mvn clean verify时出现异常:WebDriverManager已识别并下载了与本地Chrome 107匹配的Chromedriver 107.0.5304.62,但Serenity却启动了Chromedriver 90版本,导致测试运行失败。
相关日志
11:36:55.771 [pool-2-thread-1] INFO n.s.c.w.d.ChromeDriverProvider - Using automatically driver download 11:36:56.248 [pool-2-thread-1] INFO i.g.bonigarcia.wdm.WebDriverManager - Using chromedriver 107.0.5304.62 (since Chrome 107 is installed in your machine) 11:36:56.258 [pool-2-thread-1] INFO i.g.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as /Users/user69/.m2/repository/webdriver/chromedriver/mac64/107.0.5304.62/chromedriver 11:36:56.772 [pool-2-thread-1] INFO n.s.c.w.d.ProvideNewDriver - Instantiating driver 11:36:56.774 [pool-2-thread-1] INFO n.s.c.w.d.ProvideNewDriver - Driver capabilities: Capabilities {acceptInsecureCerts: false, browserName: chrome, chrome.switches: --start-maximized;--test-ty..., goog:chromeOptions: {args: [--start-maximized, --test-type, --no-sandbox, --ignore-certificate-errors;\n, --disable-popup-blocking, --disable-default-apps, --disable-extensions-file-a..., --incognito, --disable-infobars, --disable-gpu, --headless], extensions: []}, loggingPrefs: org.openqa.selenium.logging...} Starting ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429}) on port 48795 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully.
报错信息
Caused by: net.thucydides.core.webdriver.DriverConfigurationError: Could not instantiate new WebDriver instance of type class org.openqa.selenium.chrome.ChromeDriver (session not created: This version of ChromeDriver only supports Chrome version 90 Current browser version is 107.0.5304.110 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
解决方案
- 指定驱动来源为WebDriverManager:在
src/test/resources/serenity.properties中添加配置,让Serenity优先使用WebDriverManager管理的驱动:serenity.driver.source = webdrivermanager - 强制指定驱动路径:如果上述配置无效,直接在
serenity.properties中设置WebDriverManager下载的驱动路径:webdriver.chrome.driver = /Users/user69/.m2/repository/webdriver/chromedriver/mac64/107.0.5304.62/chromedriver - 清理旧驱动缓存:手动删除本地M2仓库中Chromedriver的旧版本文件夹(即
/Users/user69/.m2/repository/webdriver/chromedriver/下的90版本目录),只保留匹配的107版本。 - 更新依赖版本:检查
pom.xml中Serenity和WebDriverManager的依赖版本,确保二者兼容,可升级到最新稳定版避免冲突。 - 刷新Maven依赖:执行命令强制更新依赖,清除缓存的旧依赖:
mvn clean install -U
内容的提问来源于stack exchange,提问作者amadain
相关产品推荐
相关产品推荐

