成功完成场景后,cucumberjs 无限期地挂起。我怎样才能停止这种情况?
我在 npm/nodejs 上运行了一个 cucumberjs。
package.json:
{
"name": "foo-test-automation",
"version": "1.1.0",
"description": "Integration Regression UI Test Automation for Foo application",
"main": "fooAutoTest.js",
"scripts": {
"start": ". .env; node ./node_modules/.bin/cucumber-js --tags @RegressionTestSuite --format json:./results/log_`date +\\\"%Y\\\\%m\\\\%d_%H%M\\\"`.json",
},
完成后,cumber似乎在后台运行
$ npm run new
............................
5 scenarios (5 passed)
28 steps (28 passed)
0m37.701s
我寻找挂起的进程:
Hucks-MacBook-Pro:~ huckcarignan$ ps aux | grep node
huckcarignan 25252 0.0 0.0 4287512 856 s004 S+ 12:30PM 0:00.00 grep node
huckcarignan 18365 0.0 0.2 4652124 40804 s000 S+ 11:33AM 0:02.64 node ./node_modules/.bin/cucumber-js --tags @New --format json:./results/log_"20190521_1133".json
huckcarignan 18362 0.0 0.0 4280924 868 s000 S+ 11:33AM 0:00.01 sh -c . .env; node ./node_modules/.bin/cucumber-js --tags @New --format json:./results/log_`date +\"%Y\\%m\\%d_%H%M\"`.json
所以我什么也没注意到。
我的 hooks.js 中是否缺少某些内容:
const { BeforeAll, AfterAll } = require('cucumber');
const puppeteer = require('puppeteer');
const timestamp = require('time-stamp');
require('dotenv').config();
BeforeAll(async function() {
this.browser = await puppeteer.launch({
headless: (process.env.HEADLESS === 'true'),
slowMo: parseInt(process.env.SLOWMO),
defaultViewport: {
width: parseInt(process.env.SCREEN_SIZE_WIDTH),
height: parseInt(process.env.SCREEN_SIZE_HEIGHT)
}
});
this.page = await this.browser.newPage();
});
AfterAll(async function() {
// Teardown browser
if (this.browser) {
await this.browser.close();
}
});
如有任何帮助,我们将不胜感激。
更新 1 我尝试将 AfterAll 替换为: //异步 promise 毕竟(函数(){ 返回 Promise.resolve(); });
但它仍然挂起(但浏览器打开)
最佳答案
根据( CLI reference ),您应该能够将“--exit”添加到 npm 命令的末尾。所以它看起来像这样:
./node_modules/.bin/cucumber-js --tags @RegressionTestSuite --format json:./results/log_`date +\\\"%Y\\\\%m\\\\%d_%H%M\\\"`.json --exit
其中提供了一些有用的提示,可帮助您找出问题发生的原因以及如何解决该问题。
关于node.js - 场景完成后如何停止 cucumberjs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56242859/