Testing web apps using TestCafe | Applitools Documentation

Running Tests with Applitools

Prerequisites

  1. A free Applitools account and Applitools API KEY
    Tip: Unsure how to find your API key?
    Read Retrieving your API key to find your API key.

  2. Node.js

  3. Git
    Note: Installing git is optional

  4. Google Chrome Browser

Running the Example Project

  1. Clone or download the repository and navigate to that folder

    git clone https://github.com/applitools/tutorial-testcafe.git
    cd tutorial-testcafe
    

    Note: you can alternatively download the project as a Zip file and extract it

  2. Install the dependencies

    npm install
    
  3. Run the example test

    To run all of the tests, run:

    APPLITOOLS_API_KEY="[Your API Key]" npm run test
    

Adding Applitools Eyes to an Existing Node.js TestCafe Project

Install Applitools Eyes dependencies:

npm install @applitools/eyes-testcafe --save-dev

Sample test

// next line is optional, just for IDEs autocomplete :
/// <reference types="@applitools/eyes-testcafe" />

import { Eyes, ConsoleLogHandler, ClassicRunner, VisualGridRunner } from "@applitools/eyes-testcafe/dist/index";
import { Selector } from 'testcafe';

// Initialize the eyes
const runner = new VisualGridRunner();
const eyes = new Eyes(runner);

// Set page used in the test
fixture`Testcafe Demo App`.page`https://sandbox.applitools.com/bank`
    // Call Close on eyes to let the server know it should display the results
    .afterEach(async () => eyes.close())
    .after(async () => {
        // Wait and collect all test results
        // we pass false to this method to suppress the exception that is thrown if we
        // find visual differences
        let allTestResults = await eyes.waitForResults(false)
        // Print results
        console.log(allTestResults)
    });

test('ultraFastTest', async t => {
    await eyes.setLogHandler(new ConsoleLogHandler(true));
    // Call Open on eyes to initialize a test session
    await eyes.open({
        t, // pass testcafe contorller
        appName: 'Demo App - Testcafe - Ultrafast',
        testName: 'Smoke Test - Testcafe - Ultrafast',
    });

// check the login page with fluent api, see more info here
    // https://applitools.com/docs/topics/sdk/the-eyes-sdk-check-fluent-api.html
    await eyes.checkWindow({
        tag: "Login Window",
        target: 'window',
        fully: true
    });

await t
        .typeText(Selector("#username"), "Chris")
        .typeText(Selector("#password"), "CorrectHorseBatteryStaple")

// This will create a test with two test steps.
    await t.click('#log-in')

// Check the app page
    await eyes.checkWindow({
        tag: "App Window",
        target: 'window',
        fully: true
    })
});

Note that you may set the API key, concurrency (number of parallel screenshots), browsers X viewports, etc in the applitools.config.js file in the root directory.

module.exports = {
    apiKey: process.env.APPLITOOLS_API_KEY || 'your APPLITOOLS_API_KEY',
    //
    browser: [
        // Add browsers with different viewports
        {width: 800, height: 600, name: 'chrome'},
        {width: 700, height: 500, name: 'firefox'},
        {width: 1600, height: 1200, name: 'ie11'},
        {width: 1024, height: 768, name: 'edgechromium'},
        {width: 800, height: 600, name: 'safari'},
        // Add mobile emulation devices in Portrait mode
        {deviceName: 'iPhone X', screenOrientation: 'portrait'},
        {deviceName: 'Pixel 2', screenOrientation: 'portrait'}
    ],
    // set batch name to the configuration
    batchName: 'Ultrafast Batch',
    // specify Eyes concurrency level
    testConcurrency: 1,
}

More information

The @applitools/eyes-testcafe npm package page contain more information about advanced configuration, best practices and troubleshooting. Visit eyes-testcafe SDK repo to find out more about what's possible with Applitools' TestCafe SDK.

Taking the next steps with Applitools Eyes

Congratulations on completing this quickstart! There's still so much to learn about visual testing with Applitools, but you're off to a great start.