Skip to content

Instantly share code, notes, and snippets.

@dustinleblanc
Created March 18, 2018 17:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinleblanc/c49b020419e70f70b40353b3d05a9735 to your computer and use it in GitHub Desktop.
Save dustinleblanc/c49b020419e70f70b40353b3d05a9735 to your computer and use it in GitHub Desktop.
Setting up Laravel Dusk with ChromeDriver and Lando
name: cool-app
recipe: laravel
compose:
- docker-compose.yml
config:
php: '7.1'
via: nginx
webroot: public
database: postgres
cache: redis
services:
appserver:
composer:
phpunit/phpunit: '*'
testdb:
type: postgres
creds:
user: laravel
password: laravel
database: laravel
node:
type: node:latest
tooling:
phpunit:
service: appserver
redis-cli:
service: cache
yarn:
service: node
node:
service: node
npm:
service: node
robo:
service: appserver
cmd: 'vendor/bin/robo'
version: '3'
services:
chromedriver:
image: robcherry/docker-chromedriver:latest
expose:
- "4444"
environment:
CHROMEDRIVER_WHITELISTED_IPS: ""
CHROMEDRIVER_URL_BASE: "/wd/hub"
security_opt:
- seccomp:unconfined
<?php
namespace Tests;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
return RemoteWebDriver::create(
'http://chromedriver:4444/wd/hub', DesiredCapabilities::chrome()
);
}
@colynb
Copy link

colynb commented Jun 20, 2018

I tried this but I get this error: Could not resolve host: chromedriver

@mhetreramesh
Copy link

I get following error with this:

Facebook\WebDriver\Exception\InvalidSessionIdException: invalid session id

@mhetreramesh
Copy link

I get following error with this:

Facebook\WebDriver\Exception\InvalidSessionIdException: invalid session id

Just for the record: I've found a solution for this, just have to add volume to the container:

volumes:
      - /dev/shm:/dev/shm

my docker-compose.yml looks like:

version: '3'

services:
  chromedriver:
    image: robcherry/docker-chromedriver:latest
    volumes:
      - /dev/shm:/dev/shm
    expose:
      - "4444"
    environment:
      CHROMEDRIVER_WHITELISTED_IPS: ""
      CHROMEDRIVER_URL_BASE: "/wd/hub"
    security_opt:
      - seccomp:unconfined

@basepack
Copy link

basepack commented Oct 8, 2020

@dustinleblanc is this still your current Dusk Testing setup for Lando?

Because after much fiddling I keep getting the error: Could not resolve host: chromedriver

@dustinleblanc
Copy link
Author

This is definitely out of date, but the general concepts should still work, these days I'd use a compose service rather than including a docker-compose file, and I might use the selenium container instead of the robcherry/chromedriver one. My work over the past couple of years just hasn't included much browser testing. I could probably figure out an updated version of this with a bit of work though. If I have time I might do just that.

@basepack
Copy link

basepack commented Oct 9, 2020

Well if you are willing to create a small guide for it as you mentioned somewhere it would be great! Because, having spend half a day to get this working I gave up for now.

I have no clue why the appserver cannot reach the chromedriver while they are in the same docker network. I keep getting that Could not resolve host: chromedriver error.

But thanks for your examples so far!

@tylers-username
Copy link

Inspired by @dustinleblanc's config, see an updated solution here for making the chromedriver and laravel dusk work within Lando.

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