Skip to content

Instantly share code, notes, and snippets.

@dustinleblanc
Created March 18, 2018 17:29
Show Gist options
  • 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()
);
}
@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