下面是一些非常简单的代码。在我的应用程序中,我需要在一个节点脚本中运行runner两次,每次都使用我动态提供的不同设置。但是,当我第二次尝试调用nightwatch.runner时,它将永远不会运行。我做错了什么吗?
var nightwatch = require("nightwatch")
var runcount = 0
function run() {
// the second time it gets here, nightwatch.runner wont run. the callback will never fire.
nightwatch.runner({
config: "nightwatch.conf.js"
}, function(success) {
runcount += 1
if (runcount === 1) {
// run again
run()
} else {
finish()
}
})
}
function finish() {
console.log("finish")
}
run()发布于 2018-02-14 19:54:35
看起来Nightwatch在两次运行之间保持了一些全局状态,这导致了意外的行为。为了避免这种情况,我建议您使用child_process在单独的进程中生成Nightwatch runners:
var spawn = require('child_process').spawn;
var runcount = 0
function run() {
// the second time it gets here, nightwatch.runner wont run. the callback will never fire.
spawn('nightwatch', ['-c', 'nightwatch.conf.js'], { stdio: 'inherit' }).on('close', function() {
runcount += 1
if (runcount === 1) {
// run again
run()
} else {
finish()
}
})
}
function finish() {
console.log("finish")
}
run()发布于 2018-02-14 01:44:08
它不会运行,因为它最有可能尝试用相同的端口启动两个selenium进程。
如果您需要并行运行测试,您可以通过指定多个测试设置在nightwatch中执行此操作。点击这里查看:http://nightwatchjs.org/guide/#parallel-running
发布于 2019-09-20 10:52:41
基于@akm解决方案
var spawn = require('child_process').spawn,
times = 10,
runcount = 0;
function run() {
// the second time it gets here, nightwatch.runner wont run. the callback will never fire.
spawn('./node_modules/.bin/nightwatch', ['-e', 'default,firefox'], {
stdio: 'inherit'
})
.on('close', function() {
runcount += 1
if (runcount <= times) {
console.log('Running test #', runcount);
// run again
run()
} else {
finish()
}
})
.on('error', function(err) {
console.log('Error', err);
})
}
function finish() {
console.log('Test proccess was completed');
}
run()https://stackoverflow.com/questions/48770252
复制相似问题