ClientFunction Object

A client function that can return any serializable value from the client side.

Use the ClientFunction constructor to create a client function.

import { ClientFunction } from 'testcafe';

const getWindowLocation = ClientFunction(() => window.location);

Call the client function with the await keyword to execute it.

import { ClientFunction } from 'testcafe';

const getWindowLocation = ClientFunction(() => window.location);

fixture`ClientFunction`
    .page`https://devexpress.github.io/testcafe/example/`;

test('Check location', async t => {
    const location = await getWindowLocation();

    await t.expect(location.href).eql('https://devexpress.github.io/testcafe/example/');
});

You can overwrite client function options via the ClientFunction’s with method.

For more information, see Obtain Client-Side Info.