Testcafe how to reload actual page

淺唱寂寞╮ 提交于 2019-12-10 17:53:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!