MISCELLANEOUS

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

User action target

Identifies one or more webpage elements; and accepts the following object types.

  • DOM Element
  • jQuery object (with one or more elements)
  • CSS selector (String)
  • Function that returns any of the above
  • Array of any of the above

You can also use web elements that have contentEditable attributes as a target element for TestCafe user actions.

Used in the following functions: act.click, act.rclick, act.dblclick, act.drag, act.hover, act.type

Mouse action options

Provides additional information about the mouse action.

{    
    ctrl: false | true,
    alt: false | true,
    shift: false | true,
    meta: false | true,
    offsetX: Integer,
    offsetY: Integer,
    caretPos: Integer
}

ctrl, alt, shift, meta - Boolean (optional). Indicates which modifier keys are to be pressed during the mouse action. By default, none will be pressed.
offsetX, offsetY - Integer (optional). Mouse pointer coordinates set relative to the top-left corner of the target element. If not specified, TestCafe will move the mouse pointer to the center of the target element.
caretPos - Integer (optional). Specifies the target caret position if the action is performed on a text input field. If not specified, the caret will be set to the end of the content of the input field.

Used in the following functions: act.click, act.rclick, act.dblclick, act.drag, act.hover

Typing action options

Specifies the options that provide additional information about a typing operation.

{
    replace: false | true,
    ctrl: false | true,
    alt: false | true,
    shift: false | true,
    meta: false | true,
    offsetX: Integer,
    offsetY: Integer,
    caretPos: Integer
}

replace: Boolean (optional). true to remove the current text in the target element, and false to leave the text as is. The default is false.
ctrl, alt, shift, meta: Boolean (optional). Indicates which modifier keys are to be pressed during the mouse action. By default, none will be pressed.
offsetX, offsetY: Integer (optional). Specifies the mouse pointer coordinates relative to the target element's top-left corner. The element will be clicked in this position to receive input focus. If these parameters are not specified, TestCafe will move the mouse pointer to the center of the target element.
caretPos: Integer (optional). Specifies where to set the caret before typing. If not specified, the caret will be set to the end of content of the input field.

Used in functions: act.type

containsExcludeChildren() Selector

Selects all elements that contain the specified text. Text within child nodes is ignored.

$(':containsExcludeChildren(text)')

The following example shows how to use this selector to identify checkboxes. (TestCafe Example Page)

'@test'['Click Checkboxes and Check State'] = {
    'Click two checkbox labels': function () {
        var labels = [$(':containsExcludeChildren(Support for testing on remote devices)'),
            $(':containsExcludeChildren(Reusing existing JavaScript code for testing)')
        ];
        act.click(labels);
    },
    'Confirm checked state': function () {
        ok($('#testing-on-remote-devices').is(':checked'));
        ok($('#re-using-existing-javascript').is(':checked'));
    }
};

Important note

When TestCafe searches for the specified text content, it clears every string it encounters of all characters that are not numbers, latin or cyrillic letters before comparing it to the provided string.

attrRegExp() Selector

Selects elements by checking whether the value of an attribute matches the specified regular expression.

$(':attrRegExp(attributeName:/regExp/)')