在过去的几周中,我有一个小小的沙盒项目正在研究中,以学习实施TestCafe运行程序的来龙去脉。
除了一个问题,我已经设法解决了所有问题。在这一点上,我已经尽力想了一切。 审查了以下类似问题:
How to get the testCafe exit code
但是我的问题仍然存在。
所以我知道其他人也遇到了同样的问题,因为我的同事说他在实施过程中也遇到了同样的问题。
由于我现在知道我没有选择权,因此我在此发布问题,希望有人能找到解决方案。感谢您抽出宝贵的时间来解决我的问题。
执行以下代码时,在返回returnData之后;执行后,永远不会执行.then语句,因此永不终止TestCafe命令和浏览器窗口。
仅供参考,以下代码是使用纯NodeJS 否 ES6实现的CommonJS,因为这是启动TestCafe(app.js)的代码,而不是脚本代码。>
...**Boiler Plate testcafe.createRunner() Code**...
console.log('Starting test');
var returnData = tcRunner.run(runOptions);
console.log('Done running tests');
return returnData;
})
.then(failed => {
console.log(`Test finished with ${failed} failures`);
exitCode = failed;
if (argv.upload) return upload(jsonReporterName);
else return 0;
testcafe.close();
process.exit(exitCode);
})
.then(() => {
console.log('Killing TestCafe');
testcafe.close();
process.exit(exitCode);
});
我知道在这种情况下还有很多其他因素,例如我说过我对runOptions的研究:
const runOptions = {
// Testcafe run options, see: https://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/runner.html#run
skipJSErrors: true,
quarantineMode: true,
selectorTimeout: 50000,
assertionTimeout: 7000,
speed: 0.01
};
我可以说是访问此问题和项目的最佳方法,所有代码都是克隆git lab repo:
> git clone "https://github.com/SethEden/CAFfeinated.git"
然后检出我一直在使用此问题的分支:master 您将需要在系统上创建一个环境变量,以告诉框架测试站点配置系统应使用哪个子路径。
CAFFEINATED_TEST_SITE_NAME值:SethEden
您还需要执行其他一些命令:
> npm install
> npm link
然后执行命令以运行所有测试(目前仅为1)
> CAFfeinated
输出应如下所示:
$ CAFfeinated Starting test Done running tests Running tests in: - Chrome 76.0.3809 / Windows 10.0.0 LodPage Got into the setup Test Got to the end of the test1, see if it gets here and then the test is still running? √ LodPage
这时,浏览器仍将旋转,并且命令行仍然繁忙。您可以从上面的控制台输出中看到,已经输出了“完成运行的测试”控制台日志,并且由于已经执行了“ Got to the test1,...”控制台日志,因此应该进行测试/固定,作为test.after(...)的一部分运行。因此,接下来要执行的事情应该是在带有.then(())调用的app.js中.....但是不是。是什么赋予了?有什么想法吗?
我正在寻找专门解决此问题的方法,不仅是为了解决问题,而且将来其他人也不会陷入同样的陷阱。我一定缺少一些魔术酱,这对其他人可能很明显,但对我或对JavaScript和NodeJS,ES6和TestCafe相对较新的其他人却不那么明显。