Using TestCafe with Gulp

If you are using Gulp to organize your build process, you can easily integrate TestCafe into the workflow.

Suppose you have a project that uses Gulp.js to run build tasks. To integrate TestCafe into the project, go through these steps.

Step 1 - Install TestCafe Gulp Plugin

To install the TestCafe Gulp plugin, execute the following command from your project's root directory.

npm install --save-dev gulp-testcafe

Step 2 - Create a TestCafe Gulp Task

Open Gulpfile.js and add a task that runs TestCafe tests.

const gulp     = require('gulp');
const testcafe = require('gulp-testcafe');

gulp.task('run-testcafe-tests', () => {
    return gulp
        .src('tests/test.js')
        .pipe(testcafe({ browsers: ['chrome', 'firefox'] }));
});

This task runs tests from the tests/test.js file in Chrome and Firefox.

For a complete API Reference, see the plugin page.

Step 3 - Run the TestCafe Task

Run this task through the command line.

gulp run-testcafe-tests

Gulp must be installed globally to run tasks from the command line.

Alternatively, you can create and run a dependent task.

gulp.task('publish', ['run-testcafe-tests'], () => {
    /* ... */
});