我正在使用带有 Amazon Linux 2(Karoo)的 AWS EC2 实例,通过无头 Chrome 使用 Selenium WebDriver 运行测试自动化。
升级到 Chrome 114(稳定版)时,ChromeDriver 报告 Chrome 在启动时崩溃。
======= starting test SeleniumTest.testChromeDriverOnGoogle() =======
13:04:42.Jul INFO org.example.TestConfig.getEnvironment() - environment: DEV
13:04:42.Jul INFO org.example.TestConfig.getHeadless() - headless: true
13:04:42.Jul INFO org.example.TestConfig.getBrowserName() - browserName: chrome
13:04:42.Jul INFO org.example.TestConfig.getBrowserVersion() - browserVersion: 114
13:04:42.Jul INFO org.example.TestConfig.getChromeBinary() - chromeBinary: /opt/google/chrome/google-chrome
13:04:42.Jul INFO org.example.TestConfig.getWindowSize() - windowSize: 1200x720
13:04:42.Jul INFO i.github.bonigarcia.wdm.WebDriverManager.resolveDriverVersion() - Using chromedriver 114.0.5735.90 (resolved driver for Chrome 114)
13:04:42.Jul INFO i.github.bonigarcia.wdm.WebDriverManager.exportDriver() - Exporting webdriver.chrome.driver as /home/runner/.cache/selenium/chromedriver/linux64/114.0.5735.90/chromedriver
13:04:42.Jul INFO org.example.SeleniumTest.getChromeDriver() - headless: true
13:04:42.Jul INFO org.example.SeleniumTest.getChromeDriver() - chromeBinary: /opt/google/chrome/google-chrome
13:04:42.Jul INFO org.example.SeleniumTest.getChromeDriver() - chromeOptions: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --allow-insecure-localhost, --start-maximized, --disable-gpu, --disable-dev-shm-usage], binary: /opt/google/chrome/google-c..., extensions: []}}
Jul 05, 2023 1:04:42 PM org.openqa.selenium.remote.service.DriverService$Builder getLogOutput
INFO: Driver logs no longer sent to console by default; https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output
======= ending test SeleniumTest.testChromeDriverOnGoogle() =======
Error: org.mms.SeleniumTest.testChromeDriverOnGoogle -- Time elapsed: 0.225 s <<< ERROR!
org.openqa.selenium.SessionNotCreatedException:
Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'ip-10-55-20-37.ec2.internal', ip: '10.55.20.37'
Build info: version: '4.10.0', revision: 'c14d967899'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.294-220.533.amzn2.x86_64', java.version: '17.0.7'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --allow-insecure-localhost, --start-maximized, --disable-gpu, --disable-dev-shm-usage], binary: /opt/google/chrome/google-c..., extensions: []}}]}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140)
...
这里,从命令行尝试:
sh-4.2$ cat /etc/system-release-cpe
cpe:2.3:o:amazon:amazon_linux:2
h-4.2$ /opt/google/chrome/google-chrome --version
Google Chrome 114.0.5735.198
sh-4.2$ /opt/google/chrome/google-chrome -h
Segmentation fault
sh-4.2$ /opt/google/chrome/google-chrome --headless https://google.com
[0705/125426.171854:ERROR:socket.cc(120)] recvmsg: Connection reset by peer (104)
Trace/breakpoint trap
我尝试过其他各种标志,例如:
sh-4.2$ /opt/google/chrome/google-chrome --headless=new --disable-extensions --disable-gpu --disable-sandbox --disable-dev-shm-usage https://google.com
[0705/125611.372504:ERROR:socket.cc(120)] recvmsg: Connection reset by peer (104)
Trace/breakpoint trap
我也尝试了 Chrome 115 测试版,它仍然会出现间歇性崩溃,有时无法关闭——显然是与 Chromedriver 114 交互时出现了一些问题。
还有其他人见过这个问题或类似的问题吗(Amazon Linux 2 基于 RH/Fedora 7)——并找到了解决方法?
除此之外,我可以在哪里获得旧版本的 Chrome(例如 Chrome 112)?