Automated browser testing for the modern web development stack

testcafe

A Node.js tool to automate end-to-end web testing.
Write tests in JS or TypeScript, run them and view results.

  • Works on all popular environments: TestCafe runs on Windows, MacOS, and Linux. It supports desktop, mobile, remote and cloud browsers (UI or headless).
  • 1 minute to set up: You do not need WebDriver or any other testing software. Install TestCafe with one command, and you are ready to test: npm install -g testcafe
  • Free and open source: TestCafe is free to use under the MIT license. Plugins provide custom reports, integration with other tools, launching tests from IDE, etc. You can use the plugins made by the GitHub community or make your own.

Features

Stable tests and no manual timeouts

TestCafe automatically waits for page loads and XHRs before the test starts and after each action.
It also features smart test actions and assertions that wait for page elements to appear.
You can change the maximum wait time.
If elements load faster, tests skip the timeout and continue.

Rapid test development tool

Changes in test code immediately restart the test, and you see the results instantly.

See how it works in the TestCafe Live repository.

Latest JS and TypeScript support

TestCafe supports the latest JavaScript features, including ES2017 (for example, async/await).
You can also use TypeScript
if you prefer a strongly typed language.

Detects JS errors in your code

TestCafe reports JS errors that it finds on the webpage.
Tests automatically fail because of that.
However, you can disable this.

Concurrent tests launch

TestCafe can open multiple instances of the same browser to run parallel
tests which decreases test execution time.

PageObject pattern support

The TestCafe's Test API
includes a high-level selector library, assertions, etc.
You can combine them to implement readable tests with the PageObject pattern.

const macOSInput = Selector('.column').find('label').withText('MacOS').child('input');

Easy to include in a continuous integration system

You can run TestCafe from a console, and its reports can be viewed in a CI system's interface
(TeamCity, Jenkins, Travis & etc.)

Getting Started

Installation

Ensure that Node.js (version 4 or newer) and npm are installed on your computer before running it:

npm install -g testcafe

Creating the Test

As an example, we are going to test the https://devexpress.github.io/testcafe/example page.

Create a .js or .ts file on your computer.
Note that it needs to have a specific structure: tests must be organized into fixtures.
You can paste the following code to see the test in action:

import { Selector } from 'testcafe'; // first import testcafe selectors

fixture `Getting Started`// declare the fixture
    .page `https://devexpress.github.io/testcafe/example`;  // specify the start page


//then create a test and place your code there
test('My first test', async t => {
    await t
        .typeText('#developer-name', 'John Smith')
        .click('#submit-button')

        // Use the assertion to check if the actual header text is equal to the expected one
        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
});

Running the Test

Call the following command in a command shell.
Specify the target browser
and file path.

testcafe chrome test1.js

TestCafe opens the browser and starts executing the test.

Important! Make sure to stay in the browser tab that is running tests.
Do not minimize the browser window. Tests are not guaranteed to execute correctly
in inactive tabs and minimized browser windows because they switch to a lower resource consumption mode.

GitHub