我正在将TestCafe与Cucumber.js一起使用,但我不知道如何重新加载页面。 Testcafe文档说要使用 .eval(()=> location.reload(true)) 这给了我以下错误:
eval无法隐式解析应在其上下文中运行的测试。如果您需要从Node.js API回调中调用eval,请首先通过eval的
.with({ boundTestRun: t })
方法手动传递测试控制器。请注意,您不能在测试代码之外执行eval。
这是我的BDD方案:
When('User hard refreshes the page', async () => {
await testController
.eval(() => location.reload(true))
});
答案 0 :(得分:1)
您可以使用ClientFunction
代替t.eval
:
import { ClientFunction } from 'testcafe';
When('User hard refreshes the page', async () => {
const reloadPage = ClientFunction(() => location.reload(true), { boundTestRun: testController });
await reloadPage();
});