ingo
ingo

Reputation: 856

Testcafe Page reload

How I can reload the current page with testcafe? I found

.eval(() => location.reload(true))

But it looks like an old code, current TestCafe do not understand this. (No function error)

Upvotes: 3

Views: 2213

Answers (3)

Sri
Sri

Reputation: 1

Simple and better solution is use the below code snippet to to re-load the page in testcafe.

await t.eval(() => location.reload(true));

Upvotes: 0

Brine
Brine

Reputation: 3731

I tried to post this to all the eval answers of this question but got modded... hopefully I can add some more context lest people continue to do this wrong.

Don't use eval; the better way is to make use of Testcafe's ClientFunction instead. I use something like this in my base page object:

  async refresh () {
    await ClientFunction(() => {
      document.location.reload();
    })();
  }

then in your test, call it with something like myPage.refresh()

Upvotes: 0

mlosev
mlosev

Reputation: 5227

It's the correct way to reload the tested page. See a full test example:

import { Selector } from 'testcafe';

fixture `New Fixture`
    .page ('https://devexpress.github.io/testcafe/example/');

test('New Test', async t => {
    await t.typeText('#developer-name', 'Peter Parker');

    await t.eval(() => location.reload(true));

    await t
        .wait(3000)
        .expect(Selector('#developer-name').value).eql('');
});

Upvotes: 6

Related Questions