gpt4 book ai didi

testing - 如何获取 testCafe 退出代码

转载 作者:行者123 更新时间:2023-11-28 19:56:23 26 4
gpt4 key购买 nike

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

如果我通过 cucumber 运行 puppeteer,我不会遇到这个问题。我认为这种行为是由于我在 Hook 文件中设置的方式造成的,我没有正确解释测试咖啡馆退出代码。

在我的钩子(Hook)文件中,我正在创建一个 testCafe 运行器,在我的 Before 钩子(Hook)中,然后在我的 after 钩子(Hook)中关闭它。

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

比如close函数返回的exit code是什么还是什么?

最佳答案

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();
});

这里,如果发现failedCount > 0,可以调用process.exit

关于testing - 如何获取 testCafe 退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57084331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com