testing - 在 TestCafe 中测试期间在浏览器控制台中运行命令

标签 testing automated-tests e2e-testing web-testing testcafe

我想在 TestCafe 测试期间包含此命令。我发现我可以使用客户端函数和 t.eval 执行 JavaScript 代码,但我不知道如何继续。

测试时需要自动执行的命令:

document.querySelector(".Watchlist--form").submit()

我该怎么做?

最佳答案

如果无法使用test actions要提交表单,您需要创建一个 Client Function这样做:

import { Selector, ClientFunction } from 'testcafe';

const submitAction = ClientFunction(() => {
    document.querySelector(".Watchlist--form").submit();
});

fixture `My fixture`
    .page `http://example.com`;

test('My test', async t => {
    // Some actions and assertions before the submit action
    await t
        .click(Selector(...))
        ...
        .expect(...).ok();

    // Submit action
    await submitAction();

    // Some actions and assertions after the submit action
    await t
        .click(Selector(...))
        ...
        .expect(...).ok();
});

关于testing - 在 TestCafe 中测试期间在浏览器控制台中运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56132480/

相关文章:

javascript - 在 Mocha 中,我可以断言请求超时吗?

java - 在我的测试应用程序中缺少要测试的目标类

testing - Clojure - 测试以确保不捕获头?

c - 如果 diff 命令导致 bash 没有差异,如何输出 'passed'?

testing - Testcafe - 在运行测试时显示步骤

testing - PM2 Testcafe fs 运行导致崩溃

python - 如何测试 Django 应用程序

python-3.x - python : How can I press arrow keys randomly selenium

typescript - 如何使用 ts-node 运行 Protractor 配置文件 (.ts)?

html - 如何在 TestCafé 的输入标签内上传文件