Nightwatch.js 如何让夜班考务人员与browserstack local合作
我试图让Nightwatch内置的并行测试人员与browserstack local一起进行本地url测试 在没有browserstack local的情况下运行测试时,夜视测试人员似乎工作得很好。在未启用测试\u工作人员的情况下运行本地测试也是如此 我已经尝试了这里的例子,但没有一个使用browserstack local与夜视测试人员结合使用 当使用test_workers在本地运行时,我得到以下输出Nightwatch.js 如何让夜班考务人员与browserstack local合作,nightwatch.js,browserstack,Nightwatch.js,Browserstack,我试图让Nightwatch内置的并行测试人员与browserstack local一起进行本地url测试 在没有browserstack local的情况下运行测试时,夜视测试人员似乎工作得很好。在未启用测试\u工作人员的情况下运行本地测试也是如此 我已经尝试了这里的例子,但没有一个使用browserstack local与夜视测试人员结合使用 当使用test_workers在本地运行时,我得到以下输出 Connecting local Connected. Now testing... Pr
Connecting local
Connected. Now testing...
Process terminated with code 0.
还有其他人遇到过类似的问题吗
编辑:我已经解决了这个问题,并在下面发布了答案
我已经在下面转储了相关的配置文件
My local.conf.js
nightwatch_config = {
globals_path: 'globals.js',
output_folder: false,
src_folders: ['tests'],
selenium: {
'start_process': false,
'host': 'hub-cloud.browserstack.com',
'port': 80
},
test_workers: {
"enabled": true,
"workers":2
},
test_settings: {
default: {
desiredCapabilities: {
'browserstack.user': process.env.BROWSERSTACK_USER,
'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY,
'browserstack.local': true,
'browserstack.debug': false,
}
}
}
};
// Code to copy seleniumhost/port into test settings
for (let i in nightwatch_config.test_settings) {
if (nightwatch_config.test_settings.hasOwnProperty(i)) {
let config = nightwatch_config.test_settings[i];
config['selenium_host'] = nightwatch_config.selenium.host;
config['selenium_port'] = nightwatch_config.selenium.port;
}
}
module.exports = nightwatch_config;
local.runner.js
#!/usr/bin/env node
var Nightwatch = require('nightwatch');
var browserstack = require('browserstack-local');
var bs_local;
process.env.BROWSERSTACK_ID = new Date().getTime();
try {
process.mainModule.filename = "./node_modules/.bin/nightwatch";
// Code to start browserstack local before start of test
console.log("Connecting local");
Nightwatch.bs_local = bs_local = new browserstack.Local();
bs_local.start({ 'key': process.env.BROWSERSTACK_ACCESS_KEY }, function (error) {
if (error) throw error;
console.log('Connected. Now testing...');
Nightwatch.cli(function (argv) {
Nightwatch.CliRunner(argv)
.setup(null, function () {
// Code to stop browserstack local after end of parallel test
bs_local.stop(function () { });
})
.runTests(function () {
// Code to stop browserstack local after end of single test
bs_local.stop(function () { });
});
});
});
} catch (ex) {
console.log('There was an error while starting the test runner:\n\n');
process.stderr.write(ex.stack + '\n');
process.exit(2);
}
还有我的package.json脚本
node ./local.runner.js -c ./local.conf.js
您似乎没有指定浏览器。将配置文件修改为与以下配置文件内联:
var browserstack = require('browserstack-local');
nightwatch_config = {
src_folders : [ "local" ],
selenium : {
"start_process" : false,
"host" : "hub-cloud.browserstack.com",
"port" : 80
},
test_workers: {
"enabled": true,
"workers":2
},
common_capabilities: {
'browserstack.user': process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',
'browserstack.debug': true,
'browserstack.local': true
},
test_settings: {
default: {},
chrome: {
desiredCapabilities: {
browser: "chrome"
}
},
firefox: {
desiredCapabilities: {
browser: "firefox"
}
},
safari: {
desiredCapabilities: {
browser: "safari"
}
}
}
};
// Code to support common capabilites
for(var i in nightwatch_config.test_settings){
var config = nightwatch_config.test_settings[i];
config['selenium_host'] = nightwatch_config.selenium.host;
config['selenium_port'] = nightwatch_config.selenium.port;
config['desiredCapabilities'] = config['desiredCapabilities'] || {};
for(var j in nightwatch_config.common_capabilities){
config['desiredCapabilities'][j] = config['desiredCapabilities'][j] || nightwatch_config.common_capabilities[j];
}
}
module.exports = nightwatch_config;
这里的问题是由于local.runner.js中错误地定义了模块文件名
process.mainModule.filename = "./node_modules/.bin/nightwatch";
应该直接指向其目录中的Nightwatch文件
process.mainModule.filename = "./node_modules/nightwatch/bin/nightwatch";
我无法理解这些文件中的差异以及此解决方案有效的确切原因
答案来自于中的“套件”运行程序,我试图使用nightwatch test_workers并行测试,而不扩展到不同的浏览器。当我们准备好使用多种浏览器环境时,我会记住这一点。