我正在尝试在 docker 容器中针对最新的 chrome 版本运行 webdriver.io 测试。 当使用带有 chrome 127 的 docker 镜像时,我的测试运行良好。将 chrome 升级到 v128 或更高版本后,我收到 WebDriverError: session not Created
我的Webdriver.io能力配置:
capabilities: [{
'wdio:maxInstances': 1,
'wdio:enforceWebDriverClassic': true,
browserName: 'chrome',
acceptInsecureCerts: true,
'goog:chromeOptions': {
args: [
'--headless',
'--no-sandbox',
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-infobars',
'--disable-search-engine-choice-screen',
'--window-size=1920,1200']
}
}]
我的 Dockerfile:
FROM node:22
RUN apt-get update \
&& apt-get -y install sudo \
&& apt-get install -y unzip \
# See https://crbug.com/795759
&& apt-get install -yq libgconf-2-4 \
&& apt-get install gnupg -y \
&& apt-get install -y wget --no-install-recommends \
&& apt-get install iputils-ping -y \
&& apt-get install libpci-dev -y \
&& wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update \
&& apt-get install -y google-chrome-stable --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN echo "node ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/node
wdio 的输出:
...
16:12:35 [0-0] 2024-11-06T15:12:35.177Z INFO @wdio/utils: Started Chromedriver v130.0.6723.116 with params --port=43274 --allowed-origins=* --allowed-ips=0.0.0.0 in 105ms on port 43274
16:12:35 [0-0] 2024-11-06T15:12:35.182Z INFO webdriver: [POST] http://localhost:43274/session
16:12:35 [0-0] 2024-11-06T15:12:35.182Z INFO webdriver: DATA {
16:12:35 [0-0] capabilities: {
16:12:35 [0-0] alwaysMatch: {
16:12:35 [0-0] 'wdio:maxInstances': 1,
16:12:35 [0-0] 'wdio:enforceWebDriverClassic': true,
16:12:35 [0-0] browserName: 'chrome',
16:12:35 [0-0] acceptInsecureCerts: true,
16:12:35 [0-0] 'goog:chromeOptions': [Object]
16:12:35 [0-0] },
16:12:35 [0-0] firstMatch: [ {} ]
16:12:35 [0-0] }
16:12:35 [0-0] }
16:12:35 [0-0] 2024-11-06T15:12:35.356Z DEBUG webdriver: request failed due to response error: session not created
16:12:35 [0-0] 2024-11-06T15:12:35.357Z WARN webdriver: WebDriverError: session not created: Chrome failed to start: exited normally.
16:12:35 [0-0] (session not created: DevToolsActivePort file doesn't exist)
16:12:35 [0-0] (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) when running "http://localhost:43274/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"wdio:maxInstances":1,"wdio:enforceWebDriverClassic":true,"browserName":"chrome","acceptInsecureCerts":true,"goog:chromeOptions":{"binary":"/usr/bin/google-chrome","args":["--headless","--no-sandbox","--disable-gpu","--disable-dev-shm-usage","--disable-infobars","--disable-search-engine-choice-screen","--window-size=1920,1200"]}},"firstMatch":[{}]}}"
有什么想法吗?
我尝试添加 '--remote-debugging-port=9222' chrome 选项,不再收到 'DevToolsActivePort 文件不存在'错误,但结果仍然相同:无法创建会话:
16:44:59 [0-2] 2024-11-06T15:44:59.757Z INFO chromedriver: ChromeDriver was started successfully on port 46617.
16:44:59 [0-2] 2024-11-06T15:44:59.758Z INFO @wdio/utils: Started Chromedriver v130.0.6723.116 with params --port=46617 --allowed-origins=* --allowed-ips=0.0.0.0 in 116ms on port 46617
16:44:59 [0-2] 2024-11-06T15:44:59.761Z INFO webdriver: [POST] http://localhost:46617/session
16:44:59 [0-2] 2024-11-06T15:44:59.762Z INFO webdriver: DATA {
16:44:59 [0-2] capabilities: {
16:44:59 [0-2] alwaysMatch: {
16:44:59 [0-2] 'wdio:maxInstances': 1,
16:44:59 [0-2] 'wdio:enforceWebDriverClassic': true,
16:44:59 [0-2] browserName: 'chrome',
16:44:59 [0-2] acceptInsecureCerts: true,
16:44:59 [0-2] 'goog:chromeOptions': [Object]
16:44:59 [0-2] },
16:44:59 [0-2] firstMatch: [ {} ]
16:44:59 [0-2] }
16:44:59 [0-2] }
16:45:00 [0-2] 2024-11-06T15:45:00.893Z DEBUG webdriver: request failed due to response error: session not created
16:45:00 [0-2] 2024-11-06T15:45:00.895Z WARN webdriver: WebDriverError: session not created: Chrome failed to start: exited normally.
16:45:00 [0-2] (chrome not reachable)
16:45:00 [0-2] (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) when running "http://localhost:46617/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"wdio:maxInstances":1,"wdio:enforceWebDriverClassic":true,"browserName":"chrome","acceptInsecureCerts":true,"goog:chromeOptions":{"binary":"/usr/bin/google-chrome","args":["--remote-debugging-port=9222","--headless","--no-sandbox"]}},"firstMatch":[{}]}}"
我还尝试将 browserVersion 添加到功能中,以便 WebdriverIO 将下载并安装请求的组合,无论是否存在现有安装。我收到与 browserVersion: '128' 相同的错误。对于浏览器版本:“127”,我没有看到任何问题。
发现问题:chrome 可能由于权限问题而停止/未启动 我的 docker 是从 jenkins 作业运行的,通过将用户从“node”更改为 jenkins 用户,问题就消失了。