SeleniumHQ/docker-selenium

node-firefox with --headless rather than XVFB

graingert opened this issue ยท 12 comments

Firefox is headless as well as chrome. No need for XVFB anywhere at all now

Actually ... there is a big difference, in headless you can't enable extensions in chrome. So the experience in headless is not exactly the same as with a "real" browser. That's actually what selenium is about I think, be as close to a real experience as possible for UI automation.

Pretty sure you can in Firefox, so the point's moot

That's actually what selenium is about I think, be as close to a real experience as possible for UI automation.

That's a goal for the headless feature in Firefox as well: to run the full Firefox browser in a way that is as similar as possible to a user's experience of headed Firefox.

Any differences between headed and headless Firefox (besides headlessness, of course) are thus considered to be Firefox bugs and should be reported via this bug reporting form. For example, see bug 1375585 - Support WebGL in headless mode. Here's the full list of open bugs.

(Note: I'm the product manager for headless browsing in Firefox.)

Are you saying we are able to run Firefox without Xvfb in headless mode?
I'm getting this error:
Error: GDK_BACKEND does not match available displays

@adiohana yes but you need to configure it correctly

@graingert

any documentation to follow for this?

@graingert could you please share how to get it working with headless?

@graingert I've hit the same wall where running -headless still throws:

Error: GDK_BACKEND does not match available displays

What else needs to be done to configure headless properly?

My solution was upgrading to Firefox 59. I was using Firefox 52 which didn't have proper support for -headless. It appears the functionality didn't get properly added until Firefox 55.

Hi all,

We just made a change in the images and introduces the env var START_XVFB, you can set it to false(or anything different to true when starting the container, and then Xvfb won't be started.

docker network create grid
docker run -d -p 4444:4444 --net grid --name selenium-hub selenium/hub
docker run -d --net grid -e HUB_HOST=selenium-hub -e START_XVFB=false -v /dev/shm:/dev/shm selenium/node-chrome
docker run -d --net grid -e HUB_HOST=selenium-hub -e START_XVFB=false -v /dev/shm:/dev/shm selenium/node-firefox

If you do that, and check the running processes in the container, you'll see:

seluser@6c5028fb1dad:~$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
seluser      1  0.2  0.1  58660 18484 ?        Ss   20:30   0:00 /usr/bin/python /usr/bin/supervisord --configuration /etc/supervisord.conf
seluser     13  0.0  0.0  20988  3364 ?        S    20:30   0:00 /bin/bash /opt/bin/start-selenium-node.sh
seluser     26  5.1  1.2 7244440 129376 ?      Sl   20:30   0:03 java -jar /opt/selenium/selenium-server-standalone.jar -role node -hub http://selenium-hub:4444/grid/register -nodeConfig /opt/selenium/config.json
seluser     55  0.0  0.0  21188  3792 pts/0    Ss   20:31   0:00 bash
seluser    774  0.0  0.0  37360  3244 pts/0    R+   20:32   0:00 ps aux

So Xvfb won't run and you'll need to run tests with the headless flag set to true, e.g. in Java:

    @Test()
    public void firefoxTest() throws Exception {
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setHeadless(true);
        WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), firefoxOptions);
        driver.get("http://the-internet.herokuapp.com");
        Assert.assertEquals(driver.getTitle(), "The Internet");
        driver.quit();
    }

and for Chrome:

    @Test()
    public void chromeProfile() throws Exception {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setHeadless(true);
        WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), chromeOptions);
        driver.get("http://the-internet.herokuapp.com");
        Assert.assertEquals(driver.getTitle(), "The Internet");
        driver.quit();
    }

Therefore you can now run the images without Xvfb. I will comment again when the images with this change are released and pushed to Docker Hub.