【问题标题】:Timing assertion in testcafetestcafe 中的时序断言
【发布时间】:2019-07-25 20:32:12
【问题描述】:

我在一个 testcafe 套件中有几个测试用例。当我在 QA 环境中运行它时说我得到了这样的报告

TC1 -- 5 秒 TC2- 4 秒 TC3- 10 秒

所以每个测试用例都需要不同的时间来完成(最好的情况)现在在生产中我也希望测试用例在相同的时间内运行说生产中的 TC1 不应该超过 5 秒,我该怎么做在 testcafe 中编码? 是否有一个断言可以让我在特定时间内监控测试用例的完成情况?我想要完整的测试用例完成,而不是选择器或断言完成。

【问题讨论】:

    标签: node.js testing automated-tests e2e-testing testcafe


    【解决方案1】:

    我建议你试试TestCafe Programming Interface。在这种情况下,您可以将所有测试分成“列表”并添加自己的“运行完成”逻辑。请参阅以下“一次性”示例:

    const createTestCafe = require('testcafe');
    let testcafe         = null;
    
    createTestCafe('localhost', 1337, 1338)
        .then(tc => {
            testcafe       = tc;
            const runner   = testcafe.createRunner();
            const testList = ['tests/fixture1.js', 'tests/func/fixture3.js'];
    
            const runPromise = runner
                .src(testList)
                .browsers(['chrome'])
                .run();
    
            const deadlinePromise = new Promise(resolve => setTimeout(resolve, 10000))
                .then(throw new Error('fail'));
    
            return Promise.race(runPromise, deadlinePromise).
        })
        .then(() => {
            // success
        })
        .catch(() => {
            // fail
        });
    

    【讨论】:

    • 谢谢,这看起来正是我想要的,但无论我尝试什么测试,它都需要 12 或 15 秒,而在 deadlinePromise 中,我将 SetTimeout 设置为 10000,但测试用例仍在通过。我在这里做错什么了吗?如果自从我放置 Promice.race 以来测试需要 12 或 15 秒,我应该得到正确的失败吗?
    • Promice.race 不会终止迟到的承诺,它只是忽略它们的结果。因此,在最后期限超时引发的错误不会影响测试用例。无论如何,它们都通过了。不同之处在于您完成的位置 - 在 thencatch 块中。
    猜你喜欢
    • 2019-04-29
    • 2020-07-21
    • 2020-06-09
    • 2019-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 2020-05-13
    相关资源
    最近更新 更多