Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium with Firefox-ESR in Alpine Docker image

I'm using Selenium for testing from Java code, it's started automatically with maven, when I run mvn verify it uses gecko-driver to start new firefox instance for selenium:

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

It's working fine on my machine (and on machines of other developers) in both modes "headless" and normal. Now I'm trying to run Selenium tests with CI builds in Alpine Linux Docker container. When I tried to run it as-is, I've got an error:

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.

Then I installed all suggested tools (dbus and xvfb) from this post and started it before running tests:

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

but now Selenium tests are hadning for about 10 seconds and failing with error

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

It seems I'm doing something wrong here, what is the correct way to run headless Selenium tests in Alpine Linux Docker container? I'd prefer to configure existing Docker image instead of using Selenium images, because the migration will be expensive.


Update:

Selenium version is 3.141.59
Gecko-driver version is v0.24.0-linux64
Firefox-ESR version is: 52.8.1-r0


Update2:

xvfb, dbus and exported DISPLAY are not actually needed to run Firefox in headless mode - just run firefox --headless and it's all.

like image 635
Kirill Avatar asked Jan 29 '26 22:01

Kirill


1 Answers

As per Mozilla --headless flag is not supported in Firefox 52-esr.Headless flag was introduced in version 55 (for Linux) and 56 (Mac/Windows) . Please try on latest Firefox ESR release.

like image 151
Rahul L Avatar answered Feb 01 '26 11:02

Rahul L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!