【问题标题】:Run command in the browser's console during the test in TestCafe在 TestCafe 中测试期间在浏览器的控制台中运行命令
【发布时间】:2019-05-14 14:12:35
【问题描述】:

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

测试过程中需要自动执行的命令:

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

我该怎么做?

【问题讨论】:

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


    【解决方案1】:

    如果无法使用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();
    });
    

    【讨论】:

    • 我很高兴听到这个测试代码很有帮助。我可以请您将我们的答案标记为“解决方案”,以便其他用户更容易发现它吗?
    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2019-02-23
    相关资源
    最近更新 更多