下面是一些非常简化的代码。在我的应用程序中,我需要在节点脚本中运行两次运行器,每次都使用我提供的不同设置。然而,我第二次尝试调用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()
答案 0 :(得分:1)
看起来Nightwatch在运行之间保持一些全局状态,这会导致意外行为。为避免这种情况,我建议您使用child_process
在不同的过程中生成Nightwatch跑步者:
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()
答案 1 :(得分:0)
它不会运行,因为它很可能尝试使用相同的端口启动两个selenium进程。
如果您需要并行运行测试,则可以通过指定多个测试设置在nightwatch中执行此操作。 在这里查看:http://nightwatchjs.org/guide/#parallel-running
答案 2 :(得分:0)
基于@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()