【问题标题】:How to reload a page in testcafe cucumberjs如何在 testcafe cucumberjs 中重新加载页面
【发布时间】:2019-08-05 23:57:48
【问题描述】:

我正在使用带有 Cucumber.js 的 TestCafe,但我不知道如何重新加载页面。 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))
});

【问题讨论】:

  • 能否请您指定您的 Cucumber 集成包(testcafe-cucumber、gherking-testcafe 或其他)?
  • 嗨,安德烈,我正在使用 testcafe-cucumber。喜欢这个演示:github.com/rquellh/testcafe-cucumber

标签: javascript testing automated-tests testcafe cucumberjs


【解决方案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();
});

【讨论】:

  • 值得注意的是,实际上可能有必要删除{ boundTestRun: testController }here。
猜你喜欢
  • 2019-10-03
  • 1970-01-01
  • 2019-08-09
  • 2016-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-02
相关资源
最近更新 更多