Testcafe页面重新加载

时间:2019-09-09 09:47:06

标签: testing automated-tests e2e-testing page-refresh testcafe

如何用testcafe重新加载当前页面? 我发现

.eval(() => location.reload(true))

但是它看起来像是旧代码,当前的TestCafe对此不理解。 (无功能错误)

3 个答案:

答案 0 :(得分:4)

这是重新加载测试页面的正确方法。 查看完整的测试示例:

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('');
});

答案 1 :(得分:0)

我尝试将此问题发布到此问题的所有 import tkinter from playsound import playsound root = tkinter.Tk() def key_pressed(event): playsound('sound.wav') root.bind("<Key>", key_pressed) root.mainloop() 答案中,但被修改了...希望我可以添加更多上下文,以免人们继续做错。

不要使用eval;更好的方法是使用 Testcafe's ClientFunction 代替。我在我的基页对象中使用了这样的东西:

eval

然后在您的测试中,使用类似 async refresh () { await ClientFunction(() => { document.location.reload(); })(); }

答案 2 :(得分:0)

简单且更好的解决方案是使用以下代码片段在 testcafe 中重新加载页面。

await t.eval(() => location.reload(true));