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

Selenium Grid 4中reject-unsupported-caps配置未即时拒绝请求问题

Selenium Grid 4 reject-unsupported-caps配置未按预期生效

我正在测试Selenium Grid 4的不同配置,官方文档说明设置reject-unsupported-caps = true可让Distributor在Grid不支持请求的能力时立即拒绝请求。

本地Grid配置

Hub配置文件(hubConfig.toml)

[server]
port = 4444

[distributor]
healthcheck-interval = 10
reject-unsuported-caps = true

[logging]
structured-logs = true
log-file = "log/hubLog.log"
log-encoding = "UTF-8"
log-level = "CONFIG"

Node配置文件(nodeConfig.toml)

[server]
port = 6666

[node]
detect-drivers = true
max-sessions = 2
heartbeat-period = 10
session-timeout = 300
hub = "http://localhost:4444"

[logging]
structured-logs = true
log-file = "log/nodeLog.log"
log-encoding = "UTF-8"
log-level = "CONFIG"

测试场景

我执行了一个包含3个测试的Maven/Java/TestNG测试类,其中两个使用正确的能力配置(Chrome、Firefox),一个使用Safari。Safari测试的示例代码如下:

@Test
public void test2() throws InterruptedException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(BROWSER_NAME,"safari");
    RemoteWebDriver remoteWebDriver = new RemoteWebDriver(gridURL,caps);
    remoteWebDriver.get("http://www.google.com");
    Thread.sleep(sleepTime);
    remoteWebDriver.quit();
}

问题现象

我预期Safari测试会被Distributor立即拒绝,但实际是在会话超时后才失败,报错信息翻译为:

org.openqa.selenium.SessionNotCreatedException: 无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败

问题原因及解决方法

你在Hub配置文件中写错了配置项名称:reject-unsuported-caps 少了一个字母p,正确的配置项应该是reject-unsupported-caps。

修正后的Hub配置的distributor段应为:

[distributor]
healthcheck-interval = 10
reject-unsupported-caps = true

配置项名称拼写错误导致Grid无法识别该配置,自然不会触发“立即拒绝不支持的能力请求”的逻辑,所以请求会一直等待直到会话超时。修正配置后重启Hub,再执行Safari测试即可看到请求被立即拒绝。


内容的提问来源于stack exchange,提问作者Stayko Mitev

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 18:31:44