TEST FIXTURE API

This section describes the API available to you when creating or editing tests in code.

For a top-level overview of the test creation process - (either using the Visual Recorder or by editing JavaScript code), please refer to the Fixtures topic. When editing tests using code, you will work with .test.js files that use the syntax outlined below.

'@fixture Features';

'@page ./Features.aspx';

'@auth JohnSmith:JSp123';

'@require :my_module';
'@require ./helpers/test.js';

'@test'['Refresh'] = {
    'Click "Refresh" button': function() {
        this.prevImageSrc = getCaptcha().getImage().prop('src');
        act.click(getCaptcha().getRefreshButton());
    },
    'Check if the captchaImage url has been changed': function() {
        notEq(getCaptcha().getImage().prop('src'), this.prevImageSrc);
    }
};

function getCaptcha() {
    return dx.captcha('Captcha');
};

These files define named test fixtures with a specified entry page. Fixtures contain tests, which in turn are broken down into series of steps, each consisting of TestCafe Actions (no more than one action per step), TestCafe Assertions and custom JavaScript code. In addition to user actions and assertions, TestCafe provides a method to handle dialog windows.

Common Concepts

This section provides information about common concepts behind organizing your test code.

User Actions

Use the following methods to perform user actions. Remember that TestCafe has a maximum of one user action per test step.

Assertions

Using TestCafe assertions, you can check whether an arbitrary expression resolves to true or false, or whether two objects are equal or different.

Native Dialog Handling

If a browser displays a native message box during the test, use the functions from this section to close the dialog as required, and avoid test failure.

Miscellaneous

This section lists utility data structures, keywords and selectors used by testing functions.