Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@ELD ELD commented May 19, 2017

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

@tboztuna

This comment has been minimized.

Copy link

@tboztuna tboztuna commented Jan 15, 2020

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