javascript - 如何在 testcafe cucumberjs 中重新加载页面

标签 javascript testing automated-tests testcafe cucumberjs

我正在将 TestCafe 与 Cucumber.js 一起使用,但我不知道如何重新加载页面。 Testcafe 文档说使用 .eval(() => location.reload(true)) 这给了我以下错误:

eval cannot implicitly resolve the test run in the context of which it should be executed. If you need to call eval from the Node.js API callback, pass the test controller manually via eval's .with({ boundTestRun: t }) method first. Note that you cannot execute eval outside the test code.

这是我的 BDD 场景:

When('User hard refreshes the page', async () => {
    await testController
        .eval(() => location.reload(true))
});

最佳答案

您可以使用 ClientFunction而不是 t.eval:

import { ClientFunction } from 'testcafe';

When('User hard refreshes the page', async () => {
    const reloadPage = ClientFunction(() => location.reload(true), { boundTestRun: testController });
    
    await reloadPage();
});

关于javascript - 如何在 testcafe cucumberjs 中重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57367321/

相关文章:

javascript - 通过一次提交保存两个模型(属于第三个模型)?

unit-testing - 当已经测试了每个组件方法时测试方法组合

testing - 使用 Composer 要求包含测试的包

java - 测试失败时不会截取 Allure 报告截图

testing - 如何使用 TestCafe 确定元素属性是否存在?

javascript - 构建命运之轮游戏,我试图获取按键事件来检测随机单词数组中的字母

javascript - 如何找到与两个数组相交的所有对象?

javascript - 鼠标悬停、鼠标悬停并单击谷歌地图上的同一标记

android - 当 Android 测试失败时,Gradle 构建失败并显示 "String Index out of range"

testing - calabash-android:是否可以忽略固定(预定义)步骤?