Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestCafe how to reload actual page

Is there a way to reload the actual tested page I'm visiting in TestCafe and not the site that TestCafe is running under. I've tried using:

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

but that just reloads the server page that TestCafe uses. So for example, if I test www.google.com, the URL in the browser after I launch TestCafe will be something like http://172.16.0.152:58486/Qf6eMxOvA/https:/www.google.com/ That is the site that reloads when I execute the code above. Is there a way to force just reloading www.google.com to actually simulate reloading the tested page?

like image 240
ruazn2 Avatar asked May 15 '19 20:05

ruazn2


People also ask

Does TestCafe use WebDriver?

TestCafe uses a URL-rewriting proxy which allows it to work without the WebDriver. This proxy injects the driver script that emulates user actions into the tested page.


1 Answers

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

You are right, you should use the code provided above to reload your test page.

Please check out the following example. The example works as expected: we check the local storage value after the page reload.

test.js:

import { ClientFunction } from 'testcafe';

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

const getLocalStorageItem = ClientFunction(key => localStorage.getItem(key));

test('local storage', async t => {
    await t.eval(() => localStorage.setItem('key', 'value'));
    await t.expect(getLocalStorageItem('key')).eql('value');
    await t.wait(2000);
    await t.eval(() => location.reload(true));
    await t.wait(2000);
    await t.expect(getLocalStorageItem('key')).eql('value');
});

Result:

Running tests in:
- Chrome 74.0.3729 / Windows 10.0.0

fixture
√ local storage


1 passed (9s)
like image 145
Vladimir A. Avatar answered Sep 22 '22 00:09

Vladimir A.