Action Options

This topic describes test action options.

Basic Action Options

Provide additional parameters for an action.

{
    speed: Number
}
Parameter Type Description Default
speed Number The speed of action emulation. Defines how fast TestCafe performs the action when running tests. A number between 1 (the maximum speed) and 0.01 (the minimum speed). If test speed is also specified in the CLI, API or in test code, the action speed setting overrides test speed. 1

Basic action options are used in the t.pressKey, t.selectText, t.selectTextAreaContent and t.selectEditableContent actions.

Example

import { Selector } from 'testcafe';

const nameInput = Selector('#developer-name');

fixture `My Fixture`
    .page `http://devexpress.github.io/testcafe/example/`

test('My Test', async t => {
    await t
        .typeText(nameInput, 'Peter')
        .typeText(nameInput, ' Parker', { speed: 0.1 });
});

Mouse Action Options

Provide additional parameters for a mouse action.

{
    modifiers: {
        ctrl: Boolean,
        alt: Boolean,
        shift: Boolean,
        meta: Boolean
    },

    offsetX: Number,
    offsetY: Number,
    speed: Number
}
Parameter Type Description Default
ctrl, alt, shift, meta Boolean Indicate which modifier keys are to be pressed during the mouse action. false
offsetX, offsetY Number Mouse pointer coordinates that define a point where the action is performed or started. If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the target element. If an offset is a negative integer, they are calculated relative to the bottom-right corner. The center of the target element.
speed Number The speed of action emulation. Defines how fast TestCafe performs the action when running tests. A value between 1 (the maximum speed) and 0.01 (the minimum speed). If test speed is also specified in the CLI or programmatically, the action speed setting overrides test speed. 1

Mouse action options are used in the t.drag, t.dragToElement and t.hover actions.

Example

import { Selector } from 'testcafe';

const sliderHandle = Selector('.ui-slider-handle');

fixture `My Fixture`
    .page `http://devexpress.github.io/testcafe/example/`

test('My Test', async t => {
    await t
        .drag(sliderHandle, 360, 0, {
            offsetX: 10,
            offsetY: 10,
            modifiers: {
                shift: true
            }
        });
});

Click Action Options

Provide additional parameters for a click action.

{
    modifiers: {
        ctrl: Boolean,
        alt: Boolean,
        shift: Boolean,
        meta: Boolean
    },

    offsetX: Number,
    offsetY: Number,
    caretPos: Number,
    speed: Number
}
Parameter Type Description Default
ctrl, alt, shift, meta Boolean Indicate which modifier keys are to be pressed during the mouse action. false
offsetX, offsetY Number Mouse pointer coordinates that define a point where the action is performed or started. If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the target element. If an offset is a negative integer, they are calculated relative to the bottom-right corner. The center of the target element.
caretPos Number The initial caret position if the action is performed on a text input field. A zero-based integer. The length of the input field content.
speed Number The speed of action emulation. Defines how fast TestCafe performs the action when running tests. A value between 1 (the maximum speed) and 0.01 (the minimum speed). If test speed is also specified in the CLI or programmatically, the action speed setting overrides test speed. 1

Click action options are used in the t.click, t.doubleClick and t.rightClick actions.

Example

import { Selector } from 'testcafe';

const nameInput = Selector('#developer-name');

fixture `My Fixture`
    .page `http://devexpress.github.io/testcafe/example/`

test('My Test', async t => {
    await t
        .typeText(nameInput, 'Pete Parker')
        .click(nameInput, { caretPos: 4 })
        .pressKey('r');
});

Typing Action Options

Provide additional parameters for a typing operation.

{
    modifiers: {
        ctrl: Boolean,
        alt: Boolean,
        shift: Boolean,
        meta: Boolean
    },

    offsetX: Number,
    offsetY: Number,
    caretPos: Number,
    replace: Boolean,
    paste: Boolean,
    speed: Number
}
Parameter Type Description Default
ctrl, alt, shift, meta Boolean Indicate which modifier keys are to be pressed while typing. false
offsetX, offsetY Number Mouse pointer coordinates that define a point where the action is performed or started. If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the target element. If an offset is a negative integer, they are calculated relative to the bottom-right corner. The center of the target element.
caretPos Number The initial caret position. A zero-based integer. The length of the input field content.
replace Boolean true to remove the current text in the target element, and false to leave the text as it is. false
paste Boolean true to insert the entire block of current text in a single keystroke (similar to a copy & paste function), and false to insert the current text character by character. false
speed Number The speed of action emulation. Defines how fast TestCafe performs the action when running tests. A value between 1 (the maximum speed) and 0.01 (the minimum speed). If test speed is also specified in the CLI or programmatically, the action speed setting overrides test speed. 1

Typing action options are used in the t.typeText action.

Example

import { Selector } from 'testcafe';

const nameInput = Selector('#developer-name');

fixture `My Fixture`
    .page `http://devexpress.github.io/testcafe/example/`

test('My Test', async t => {
    await t
        .typeText(nameInput, 'Peter')
        .typeText(nameInput, 'Parker', { replace: true });
});