如何使用testcafe重新加载当前页面?我发现
.eval(() => location.reload(true))但是它看起来像是一个旧代码,当前的TestCafe不能理解这一点。(无函数错误)
发布于 2019-09-09 22:06:39
这是重新加载测试页面的正确方法。查看完整的测试示例:
import { Selector } from 'testcafe';
fixture `New Fixture`
.page ('https://devexpress.github.io/testcafe/example/');
test('New Test', async t => {
await t.typeText('#developer-name', 'Peter Parker');
await t.eval(() => location.reload(true));
await t
.wait(3000)
.expect(Selector('#developer-name').value).eql('');
});发布于 2021-04-01 05:08:34
我试着把这个问题贴到所有的eval答案上,但是被修改了……希望我能添加更多的上下文,以免人们继续这样做错误。
不要使用eval;更好的方法是使用Testcafe's ClientFunction。我在我的基页对象中使用了类似这样的东西:
async refresh () {
await ClientFunction(() => {
document.location.reload();
})();
}然后在你的测试中,使用类似于myPage.refresh()的东西来调用它
发布于 2021-04-04 03:43:13
更简单、更好的解决方案是使用下面的代码片段在testcafe中重新加载页面。
await t.eval(() => location.reload(true));https://stackoverflow.com/questions/57851542
复制相似问题