Laravel Tutorials

Running Dusk tests on Travis CI and CircleCI

Published
Running Dusk tests on Travis CI and CircleCI image

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:

sudo: required
language: php
dist: trusty

php:
  - 7.1

install:
  - travis_retry composer install --no-interaction

before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - ./vendor/laravel/dusk/bin/chromedriver-linux &
  - cp .env.testing .env
  - php artisan serve &

script:
  - 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:

machine:
  pre:
    - sudo apt-get update; USE_PRECOMPILE=true sudo -E circleci-install php 7.1.0

  php:
    version: 7.1.0

dependencies:
  override:
    - composer install --no-interaction
test:
  pre:
    - "./vendor/laravel/dusk/bin/chromedriver-linux":
        background: true
    - cp .env.testing .env
    - "php artisan serve":
        background: true

  override:
    - php artisan dusk

Mohamed Said photo

Web Developer and Laravel Core Contributor

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Insert Middleware Before or After Existing Laravel Middleware image

Insert Middleware Before or After Existing Laravel Middleware

Read article
Laravel Herd 2: Coding Agents, Workspaces, and Cloud Deploys image

Laravel Herd 2: Coding Agents, Workspaces, and Cloud Deploys

Read article
Strict Request Input Casting in Laravel image

Strict Request Input Casting in Laravel

Read article
Prevent Duplicate File Uploads With Laravel Storage Dedupler image

Prevent Duplicate File Uploads With Laravel Storage Dedupler

Read article
Slow Job Alerts and Replica Commit IDs in Laravel 13.40 image

Slow Job Alerts and Replica Commit IDs in Laravel 13.40

Read article
Flock: A Free, Native Herd Alternative for Laravel image

Flock: A Free, Native Herd Alternative for Laravel

Read article