如何获得testCafe退出代码

时间:2019-07-17 21:34:22

标签: testcafe

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

如果我通过黄瓜来操纵木偶戏,我不会遇到这个问题。我认为这种行为是由于我在hooks文件中设置的方式所致,而我在其中没有正确解释测试咖啡馆的退出代码。

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

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

例如,关闭函数返回的退出代码是什么?

1 个答案:

答案 0 :(得分:4)

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

TestCafe仅在CLI中调用process.exit

我想您想获取有关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();
    });

在这里,如果发现failCount> 0,则可以致电process.exit