Alpine Docker 镜像中带有 Firefox-ESR 的 Selenium

标签 selenium docker firefox selenium-webdriver alpine-linux

我正在使用 Selenium 从 Java 代码进行测试,它通过 maven 自动启动,当我运行 mvn verify 它使用 gecko-driver 启动新的 selenium 的 firefox 实例:

final FirefoxOptions opts = new FirefoxOptions();
if (HEADLESS_MODE) {
  opts.addArguments(ARG_HEADLESS);
}
return new FirefoxDriver(opts);

它在我的机器(以及其他开发人员的机器)上以“ headless ”和正常两种模式运行良好。现在我正在尝试在 Alpine Linux Docker 容器中使用 CI 构建运行 Selenium 测试。当我尝试按原样运行它时,出现错误:

mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.pW1sbkcv98QN" Error: GDK_BACKEND does not match available displays.

然后我从 this post 安装了所有建议的工具(dbusxvfb)并在运行测试之前启动它:

apk add xvfb dbus
dbus-uuidgen > /etc/machine-id
export DISPLAY=:99
Xvfb $DISPLAY -ac &
mvn verify

但是现在 Selenium 测试等待了大约 10 秒并因错误而失败

1565433736375 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.1ZMsJ0Hy95V0" 1565433738424 Marionette INFO Listening on port 2828

!!! [Child][MessageChannel] Error: (msgtype=0x3E0003,name=PCompositable::Msg_Destroy) Channel error: cannot send/recv

[Child 2191] ###!!! ABORT: Aborting on channel error.: file /home/buildozer/aports/community/firefox-esr/src/firefox-52.8.1esr/ipc/glue/MessageChannel.cpp, line 2152 [Child 2191] ###!!! ABORT: Aborting on channel error.: file /home/buildozer/aports/community/firefox-esr/src/firefox-52.8.1esr/ipc/glue/MessageChannel.cpp, line 2152

!!! [Child][MessageChannel] Error: (msgtype=0x3E0003,name=PCompositable::Msg_Destroy) Channel error: cannot send/recv

看来我在这里做错了什么,在 Alpine Linux Docker 容器中运行 headless Selenium 测试的正确方法是什么?我更愿意配置现有的 Docker 镜像而不是使用 Selenium 镜像,因为迁移成本很高。


更新:

Selenium 版本是 3.141.59
Gecko 驱动程序版本为 v0.24.0-linux64
Firefox-ESR 版本为:52.8.1-r0


更新2:

xvfbdbus 和导出的 DISPLAY 实际上不需要以 headless 模式运行 Firefox - 只需运行 firefox --headless 这就是全部。

最佳答案

根据 Mozilla --headless 标志在 Firefox 52-esr 中不受支持。Headless 标志是在版本 55(适用于 Linux)和 56(Mac/Windows)中引入的。请尝试最新的 Firefox ESR 版本。

关于Alpine Docker 镜像中带有 Firefox-ESR 的 Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57441584/

相关文章:

java - Selenium 找不到可见元素

c# - 网页测试自动化框架中的问题

docker - 当我尝试从容器运行时,我的自定义节拍找不到 custombeat.yml

docker - app.war中没有主 list 属性

java - 如何在 Docker 上的 WebSphere 上运行特定配置文件?

javascript - 有没有办法阻止 Firebug 在特定站点上工作?

firefox - 如何在 Selenium Webdriver 中设置特定的 Firefox 版本?

VSTS (Azure DevOps) 中的 Selenium 屏幕截图

firefox - Firefox 中的谷歌地图缩放和滚动页面

javascript - DOMParser.parseFromString(text ,"text/html") 仅解释前 ~21,500 字节。这是一个错误吗?