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?
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With