You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Serenity配置acceptInsecureCerts=true后Selenium运行报错如何解决

问题原因

  • serenity.conf中配置的chrome.capabilities.acceptInsecureCerts=true被默认解析为字符串类型,不符合Selenium要求的布尔类型参数规则,因此抛出类型不匹配错误
  • 自定义WebDriver初始化代码存在无效配置:你构造了DesiredCapabilities对象,但最终初始化ChromeDriver时仅传入了ChromeOptions,所有针对DesiredCapabilities的配置完全没有生效,同时DesiredCapabilities属于Selenium已废弃的用法,不推荐继续使用

解决方案

方案1:修改serenity.conf配置(无需改动代码,优先推荐)

删除原有配置末尾的分号,不要给true加任何引号,确保配置被解析为布尔类型即可:

chrome.capabilities.acceptInsecureCerts = true

如果仍出现类型识别问题,可以加强制类型声明:

chrome.capabilities.acceptInsecureCerts = Boolean("true")

方案2:修正自定义WebDriver初始化代码

直接简化冗余配置,仅保留ChromeOptions的设置即可,同时要删除serenity.conf中对应的acceptInsecureCerts配置,避免配置优先级覆盖代码设置:

@Override
public WebDriver newDriver() {
    try {
        ChromeOptions options = new ChromeOptions();
        options.setAcceptInsecureCerts(true);
        return new ChromeDriver(options);
    } catch (Exception e) {
        throw new Error(e);
    }
}

验证方式

启动服务后查看ChromeDriver初始化日志,确认acceptInsecureCerts的值为无引号的true,即为配置生效。

内容的提问来源于stack exchange,提问作者Saikat...

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 05:45:01