title: Selenium with Firefox-ESR in Alpine Docker image
body: <p>I'm using Selenium for testing from Java code, it's started automatically with maven, when I run <code>mvn verify</code> it uses <code>gecko-driver</code> to start new <code>firefox</code> instance for selenium:</p>
  
  <pre class="lang-java prettyprint-override"><code>final FirefoxOptions opts = new FirefoxOptions();
  if (HEADLESS_MODE) {
    opts.addArguments(ARG_HEADLESS);
  }
  return new FirefoxDriver(opts);
  </code></pre>
  
  <p>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:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>Then I installed all suggested tools (<code>dbus</code> and <code>xvfb</code>) from <a href="https://blog.bj13.us/2016/06/11/install-a-headless-selenium-server-in-an-alpine-linux-container.html" rel="nofollow noreferrer">this post</a> and started it before running tests:</p>
  
  <pre class="lang-sh prettyprint-override"><code>apk add xvfb dbus
  dbus-uuidgen &gt; /etc/machine-id
  export DISPLAY=:99
  Xvfb $DISPLAY -ac &amp;
  mvn verify
  </code></pre>
  
  <p>but now Selenium tests are hadning for about 10 seconds and failing with error</p>
  
  <blockquote>
    <p>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</p>
    
    <h3>!!! [Child][MessageChannel] Error: (msgtype=0x3E0003,name=PCompositable::Msg_Destroy) Channel error: cannot send/recv</h3>
    
    <p>[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</p>
    
    <h3>!!! [Child][MessageChannel] Error: (msgtype=0x3E0003,name=PCompositable::Msg_Destroy) Channel error: cannot send/recv</h3>
  </blockquote>
  
  <p>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.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>Selenium version is <code>3.141.59</code><br/>
  Gecko-driver version is <code>v0.24.0-linux64</code><br/>
  Firefox-ESR version is: <a href="https://pkgs.alpinelinux.org/package/v3.7/community/x86_64/firefox-esr" rel="nofollow noreferrer"><code>52.8.1-r0</code></a><br/></p>
  
  <hr>
  
  <p><strong>Update2:</strong></p>
  
  <p><code>xvfb</code>, <code>dbus</code> and exported <code>DISPLAY</code> are not actually needed to run Firefox in headless mode - just run <code>firefox --headless</code> and it's all.</p>