Skip to content

Instantly share code, notes, and snippets.

@bonsi
Last active January 21, 2022 05:34
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bonsi/f59805f74b277bf0cf01a9b19cf9ca2c to your computer and use it in GitHub Desktop.
Save bonsi/f59805f74b277bf0cf01a9b19cf9ca2c to your computer and use it in GitHub Desktop.
Get Laravel Dusk running within (lara)dock

NOTES

Working solution for laradock

  • spin up the selenium image (selenium/standalone-chrome) as included with laradock
  • in .env.dusk.local set APP_URL=http://nginx to point to the docker nginx image
  • in tests\DuskTestCase.php replace the line 'http://localhost:9515', DesiredCapabilities::chrome() with 'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()
  • run php artisan dusk
  • ...
  • PROFIT

=========================================================================================== Directions below this point were premature workarounds.

Todo

  • xvfb-run / xvfb are not killed after running dusk

Steps

  • Build chrome + xvfb into a container:
RUN apt-get install -y wget && \
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub |  apt-key add - && \
    sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \
    apt-get update && apt-get install -y google-chrome-stable && \
    apt-get install -y xvfb
  • (re)build your container and start it

  • overload the method buildChromeProcess in the Laravel\Dusk\SupportsChrome trait by adding the following code to your tests/DuskTestCase.php:

   /**
     * Build the process to run the Chromedriver.
     *
     * @return \Symfony\Component\Process\Process
     */
    protected static function buildChromeProcess()
    {
        return (new ProcessBuilder())
                ->setPrefix('xvfb-run')
                ->setArguments([
                    '../vendor/laravel/dusk/bin/chromedriver-linux'
                ])
                ->getProcess()
                ->setEnv(static::chromeEnvironment());
    }
  • Run php artisan dusk
@ELD
Copy link

ELD commented May 19, 2017

I get a 404 Not Found when I try to run dusk using your instructions. Any idea why?

@tboztuna
Copy link

selenium can not connect to nginx container. It says 'nginx's server IP address could not be found.' .
Anyone had this problem before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment