如何获得testCafe退出代码

swi*_*201 3 testing automated-tests exit-code e2e-testing testcafe

我在通过黄瓜运行Testcafe时遇到问题。无论出于何种原因,当我通过黄瓜运行testCafe时,即使测试失败,该过程也始终会以退出代码0退出。

如果我通过黄瓜来操纵木偶戏,我不会遇到这个问题。我认为这种行为是由于我在我的钩子文件中设置了东西的方式造成的,在该文件中我没有正确解释测试咖啡馆出口代码。

在我的hooks文件中,我将在我的Before钩子中创建一个testCafe运行器,然后在我的after钩子中将其关闭。

我想知道我可以使用什么命令来获取TestCafe退出代码,而我却找不到任何信息。

例如,退出代码是从close函数返回的还是什么?

Ale*_*aev 5

TestCafe API不会调用该process.exit方法,因为它应该在自定义节点脚本中起作用。

TestCafe process.exit仅在CLI中调用。

我想您想获取有关API中失败测试的信息。该runner.run方法返回此信息。请参见以下示例:

const createTestCafe = require('testcafe');
let runner           = null;
let tc               = null;

createTestCafe('localhost', 1337, 1338)
    .then(testcafe => {
        tc     = testcafe;
        runner = tc.createRunner();
    })
    .then(() => {
        return runner
            .src('...')
            .browsers('chrome')
            .run();
    })
    .then(failedCount => {
        console.log(failedCount)

        return tc.close();
    });
Run Code Online (Sandbox Code Playgroud)

在这里,process.exit如果发现failCount> 0,则可以调用;否则,您可以调用。