我尝试使用 SSH 运行 Selenium,但出现 Chrome 崩溃错误。
通过 ssh 使用的命令:-
ssh -tt -o 'StrictHostKeyChecking=no' <ip-address> 'Xvfb :89 -ac -noreset \&;export DISPLAY=:89;./gradlew clean test --tests "testName" '
当尝试在实际机器上运行时它可以工作。
实际m/c中使用的命令:-
./gradlew clean test --tests "testName"
Chrome 版本:- 122
错误:-
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'xxxx', ip: 'xxxx'
Build info: version: '4.13.0', revision: 'ba948ece5b*'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.5.0-1015-aws', java.version: '17.0.10'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [start-maximized, --log-level=3, --disable-logging, --remote-allow-origins=*], extensions: [], prefs: {download.default_directory: /, download.directory_upgrade: true, download.prompt_for_download: false, plugins.always_open_pdf_externally: true, profile.content_settings.exceptions.automatic_downloads.*.setting: 1, profile.default_content_settings.popups: 0}}}]}]
尝试从 SSH 启动 Chrome,收到错误:-
<user>@ip:~$ Xvfb :89 -ac -noreset &
[1] 2150856
<user>@ip:~$ export DISPLAY=:89
<user>@ip:~$ /opt/google/chrome/chrome
[0328/044551.812046:WARNING:chrome_main_linux.cc(80)] Read channel
stable from /opt/google/chrome/CHROME_VERSION_EXTRA
[2151074:2151074:0328/044552.418390:ERROR:viz_main_impl.cc(196)]
Exiting GPU process due to errors during initialization
[2151036:2151036:0328/044552.718182:ERROR:object_proxy.cc(576)]
Failed to call method: org.freedesktop.ScreenSaver.GetActive:
object_path= /org/freedesktop/ScreenSaver:
org.freedesktop.DBus.Error.NotSupported: This method is not part
of the idle inhibition specification:
https://specifications.freedesktop.org/idle-inhibit-spec/latest/
[2151181:2151181:0328/044553.044279:ERROR:viz_main_impl.cc(196)]
Exiting GPU process due to errors during initialization
[2151097:7:0328/044553.295640:ERROR:command_buffer_proxy_impl
.cc(131)] ContextResult::kTransientFailure: Failed to send
GpuControl.CreateCommandBuffer.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
我不知道您的 Java 项目是什么样的,但我可以向您展示如何通过 SSH 连接直接启动 Chrome。
在尝试使用单个命令启动之前,您应该确保可以通过正常的 SSH 连接运行它。因此,创建一个 SSH 连接。
确保 Chrome 和 ChromeDriver 均安装在远程(实际路径可能会有所不同)。
$ which chrome
/usr/local/bin/chrome
$ which chromedriver
/usr/local/bin/chromedriver
没有
DISPLAY
。
$ chrome
这将给出关于缺少
DISPLAY
环境变量的错误。设置变量。
$ export DISPLAY=:89
$ chrome
这会给出相同的错误,因为虽然定义了
DISPLAY
,但没有实际的X服务器。
$ Xvfb :89 -ac -noreset &
$ export DISPLAY=:89
$ chrome
您应该会收到一些错误,但没有什么严重的错误,Chrome 应该继续在终端中运行。通过
Ctrl-C
停止它。
您可以通过告诉 Chrome 不要尝试使用 GPU 来抑制其中一些启动消息。
$ chrome --disable-gpu
好吧,现在让我们通过单个 SSH 命令启动 Chrome。
ssh -tt -o 'StrictHostKeyChecking=no' [email protected] 'Xvfb :89 -ac -noreset & export DISPLAY=:89; chrome --disable-gpu'
注意: 因为您将
Xvfb
放入背景,所以不需要在 &
后面加上 ;
。