Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thoughts's avatar

Possible to show browser window for Dusk tests via Sail?

I'm running Laravel 8 with the Docker/Sail-based setup from the docs (on a Linux Mint [Ubuntu-ish] host system). It mostly all works, including Dusk tests, which I run with "sail dusk".

However, the Dusk tests are all headless. But I want to see the browser window. (I can see the screenshots that are saved on failures, which helps a little.)

I've tried editing DuskTestCase.php and removing the --headless line.

I've added DUSK_HEADLESS_DISABLED=true to my .env.dusk.local file.

No dice. And no errors that I can see, with one exception. I don't know if this is related, but I get this in my "sail up" terminal output:

selenium_1      | [1645499305.708][SEVERE]: bind() failed: Cannot assign requested address (99)

That sounds bad... but, the tests do work, and I can't tell if that's related to trying to launch the browser window? Nothing in docker-compose.yml nor DuskTestCase.php nor my .env* refers to port 99.

I've done a ton of searching on this, and can find almost nobody talking about the same issue. So I wonder if maybe "headful" mode is not even possible when running tests in a Laravel Docker/Sail container?

Thanks for any suggestions.

0 likes
7 replies
piljac1's avatar

Never worked with Sail, but it looks like the error is related to Dusk, because Dusk uses Selenium under the hood. Have you also removed --disable-gpu (as well as --headless)? Because you need to have the GPU enabled for it to work.

collins0492's avatar

Hi, assuming you are using the selenium/standalone-chrome docker image Sail ships with then that error is normal and is usually an issue related to IPv6 so not important. To accomplish what you ask you are right to add the variable DUSK_HEADLESS_DISABLED=true to your .env file but you also need to expose port 7900 on your selenium container in your docker-compose.yml file. Something like this:

selenium:
    image: 'selenium/standalone-chrome:4.1.2-20220217'
    environment:
        LARAVEL_SAIL: 1
    volumes:
        - '/dev/shm:/dev/shm'
    ports:
        - '${FORWARD_SELENIUM_PORT:-4444}:4444'
        - '${FORWARD_SELENIUM_HEADFUL_PORT:-7900}:7900'
    networks:
        - sail

Then visit localhost:7900 and it should ask you for credentials, the default one is "secret".

This step isn't explained in the Laravel Dusk docs, it's in the SeleniumHQ/docker-selenium docker image readme on GitHub.

If the connection to port 7900 isn't working make sure you are using a version of selenium/standalone-chrome that has noVNC support.

6 likes
thoughts's avatar

Thanks for your replies. Yes, I have also removed --disable-gpu.

I've now added those port lines to the selenium: block in my docker-compose.yml file. Now, localhost:4444 works (shows a Selenium default page). But localhost:7900 doesn't work: it's trying to do something, but it's just bouncing between connection_refused and connection_reset pages.

It looks like the service is there and listening:

# netstat -petvan |grep 7900
tcp        0      0 0.0.0.0:7900            0.0.0.0:*               LISTEN      0          58451816   27469/docker-proxy  
tcp6       0      0 :::7900                 :::*                    LISTEN      0          58453441   27483/docker-proxy  

My selenium: image is defined as 'selenium/standalone-chrome' but how do I tell if it has noVNC support? I can't find a binary for this, or any config files -- just the selenium.stub file.

collins0492's avatar
Level 1

Try this image tag:

image: 'selenium/standalone-chrome:4.1.2-20220217'

This is currently working on one of my projects.

1 like
thoughts's avatar

@collins0492 This worked!

image: 'selenium/standalone-chrome:4.1.2-20220217'

I can now log in at localhost:7900 with "secret" and see the browser from my tests.

Thank you so much!

collins0492's avatar

This is my working selenium service block:

selenium:
    image: 'selenium/standalone-chrome:4.1.2-20220217'
    environment:
        LARAVEL_SAIL: 1
    volumes:
        - '/dev/shm:/dev/shm'
    ports:
        - '${FORWARD_SELENIUM_PORT:-4444}:4444'
        - '${FORWARD_SELENIUM_HEADFUL_PORT:-7900}:7900'
    networks:
        - sail

I'm then able to see the browser tests at localhost:7900

5 likes

Please or to participate in this conversation.