Running Dusk tests on Travis CI and CircleCI

Tutorials

March 30th, 2017

laravel-dusk.png

Laravel Dusk allows us to write end-to-end tests for JavaScript enabled applications by running an actual browser, which simulates an actual user interaction with our applications and provides us with a more accurate feedback on how our application behaves.

However, it wasn’t very clear how to run Dusk tests on different Continuous Integration services, so I went ahead and tried to run those tests on Travis CI and CircleCI and was able to get it to work.

Running dusk tests on Travis CI

To be able to run the tests on Travis CI, we need to use the sudo-enabled Ubuntu Trusty environment which has the correct chrome version Dusk’s standalone chromedriver needs.

We also need to use Xvfb which is an in-memory display tool that will allow us to run an actual browser on the display-less environment Travis provides, and finally we’ll have to manually run the standalone chromedriver before we run our tests.

Our .travis.yml file may look like this:

1sudo: required
2language: php
3dist: trusty
4
5php:
6 - 7.1
7
8install:
9 - travis_retry composer install --no-interaction
10
11before_script:
12 - export DISPLAY=:99.0
13 - sh -e /etc/init.d/xvfb start
14 - ./vendor/laravel/dusk/bin/chromedriver-linux &
15 - cp .env.testing .env
16 - php artisan serve &
17
18script:
19 - php artisan dusk

Running dusk tests on CircleCI

On CircleCI it’s even easier, all we need to do is manually run the standalone chrome driver and use php artisan serve to start start PHP’s built-in server:

1machine:
2 pre:
3 - sudo apt-get update; USE_PRECOMPILE=true sudo -E circleci-install php 7.1.0
4
5 php:
6 version: 7.1.0
7
8dependencies:
9 override:
10 - composer install --no-interaction
11test:
12 pre:
13 - "./vendor/laravel/dusk/bin/chromedriver-linux":
14 background: true
15 - cp .env.testing .env
16 - "php artisan serve":
17 background: true
18
19 override:
20 - php artisan dusk

Filed in:

Mohamed Said

Web Developer and Laravel Core Contributor