Victoria Cole
Victoria Cole

Reputation: 51

How to reload a page in testcafe cucumberjs

I am using TestCafe with Cucumber.js and I don't know how to reload the page. Testcafe documentation says to use .eval(() => location.reload(true)) which gives me the following error:

eval cannot implicitly resolve the test run in the context of which it should be executed. If you need to call eval from the Node.js API callback, pass the test controller manually via eval's .with({ boundTestRun: t }) method first. Note that you cannot execute eval outside the test code.

Here is my BDD scenario:

When('User hard refreshes the page', async () => {
    await testController
        .eval(() => location.reload(true))
});

Upvotes: 0

Views: 1103

Answers (1)

Andrey Belym
Andrey Belym

Reputation: 2903

You can use ClientFunction instead of t.eval:

import { ClientFunction } from 'testcafe';

When('User hard refreshes the page', async () => {
    const reloadPage = ClientFunction(() => location.reload(true), { boundTestRun: testController });
    
    await reloadPage();
});

Upvotes: 3

Related Questions