TestCafe 如何重新加载实际页面

rua*_*zn2 6 automated-tests refresh reload e2e-testing testcafe

有没有办法重新加载我在 TestCafe 中访问的实际测试页面,而不是在 TestCafe 下运行的站点。我试过使用:

await t.eval(() => location.reload(true));
Run Code Online (Sandbox Code Playgroud)

但这只会重新加载 TestCafe 使用的服务器页面。例如,如果我测试www.google.com,启动 TestCafe 后浏览器中的 URL 将类似于http://172.16.0.152:58486/Qf6eMxOvA/https:/www.google.com/ 那就是当我执行上面的代码时重新加载的站点。有没有办法强制重新加载www.google.com来实际模拟重新加载测试页面?

Vla*_* A. 6

await t.eval(() => location.reload(true));
Run Code Online (Sandbox Code Playgroud)

你是对的,你应该使用上面提供的代码来重新加载你的测试页面。

请查看以下示例。该示例按预期工作:我们在页面重新加载后检查本地存储值。

测试.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');
});
Run Code Online (Sandbox Code Playgroud)

结果:

Running tests in:
- Chrome 74.0.3729 / Windows 10.0.0

fixture
? local storage


1 passed (9s)
Run Code Online (Sandbox Code Playgroud)