问题
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?
回答1:
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)
来源:https://stackoverflow.com/questions/56157048/testcafe-how-to-reload-actual-page