Node.js 在browserstack上运行多个nightwatch实例
我把我的夜表和browserstack结合起来了。当我运行一个实例时,它工作正常。但当第一个实例工作时,有人试图在不同的浏览器上同时运行第二个测试,或者只是从项目的另一个分支运行第二个测试时,第一个实例出现错误,无法连接到页面,所以可能是第一个selenium服务器关闭连接。有什么办法吗?Ofc I在browserstack中有2个可用空间用于并行测试。 配置: nightwatch.conf.jsNode.js 在browserstack上运行多个nightwatch实例,node.js,selenium,nightwatch.js,browserstack,Node.js,Selenium,Nightwatch.js,Browserstack,我把我的夜表和browserstack结合起来了。当我运行一个实例时,它工作正常。但当第一个实例工作时,有人试图在不同的浏览器上同时运行第二个测试,或者只是从项目的另一个分支运行第二个测试时,第一个实例出现错误,无法连接到页面,所以可能是第一个selenium服务器关闭连接。有什么办法吗?Ofc I在browserstack中有2个可用空间用于并行测试。 配置: nightwatch.conf.js const chromedriver = require('chromedriver'); r
const chromedriver = require('chromedriver');
require('nightwatch-cucumber')({
cucumberArgs: [
'--require', './tests/step_definitions/hooks.js',
'--require', './tests/step_definitions',
'--format', 'json:reports/cucumber.json',
'--format-options', '{"colorsEnabled":true}',
'./tests/features'
]
});
module.exports = {
output_folder: 'reports',
custom_assertions_path: 'tests/assertions',
custom_commands_path: "./node_modules/nightwatch-commands/commands",
live_output: true,
disable_colors: false,
test_settings: {
default: {
launch_url: 'http://pptm_nightwatch:3000',
selenium_host: 'pptm_hub',
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
loggingPrefs: {
'browser': 'ALL'
}
},
selenium: {
cli_args: {
'webdriver.chrome.driver': chromedriver.path
}
},
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
loggingPrefs: {
'browser': 'ALL'
}
},
selenium: {
cli_args: {
'webdriver.chrome.driver': chromedriver.path
}
}
},
}
};
nightwatch.browserstack.conf.js
const defaultConfig = require('./nightwatch.conf');
const browserstackConfig = {
selenium: {
start_process: false,
host: 'hub-cloud.browserstack.com',
port: 80,
},
test_settings: {
default: {
desiredCapabilities: {
'browserstack.user': "bla",
'browserstack.key': "bla",
'browserstack.local': true,
},
globals: defaultConfig.test_settings.default.globals,
},
edge: {
desiredCapabilities: {
browser: 'edge',
},
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
loggingPrefs: {
'browser': 'ALL'
}
},
},
},
};
const nightwatchConfig = Object.assign({}, defaultConfig, browserstackConfig);
Object.keys(nightwatchConfig.test_settings).forEach((key) => {
const config = nightwatchConfig.test_settings[key];
config.selenium_host = nightwatchConfig.selenium.host;
config.selenium_port = nightwatchConfig.selenium.port;
config.desiredCapabilities = Object.assign(
{},
nightwatchConfig.test_settings.default.desiredCapabilities,
config.desiredCapabilities,
);
});
module.exports = nightwatchConfig;
server.js:
var _ = require('lodash'),
fs = require('fs'),
path = require('path'),
express = require('express'),
cons = require('consolidate'),
bodyParser = require('body-parser');
var PORT = 3000;
function runServer(done) {
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.engine('html', cons.lodash);
app.set('views', path.join(__dirname, './templates'));
app.set('view engine', 'html');
app.get('/page/:pageId', function(req, res){
res.status(200).render(req.params.pageId, TEMPLATE_OPTIONS);
});
app.post('/form-endpoint', function (req, res) {
res.status(200).send('<body>POST(' + JSON.stringify(req.body)+')</body>');
});
var server = app.listen(PORT, function () {
done()
});
return server;
}
module.exports = runServer;
if (require.main === module) {
runServer(function () {
console.log("Starting server on port " + PORT + ". Please visit e.g. http://localhost:" + PORT + "/page/formSimple.html");
});
}
这表示在测试仍在执行时BrowserStackLocal二进制文件正在断开连接。问题似乎是由于使用相同修饰符的BrowserStackLocal二进制文件的多个派生。让我用一个示例场景来解释这一点 测试工程师1在上午10:00运行测试让我们假设此测试运行15分钟:这将在测试工程师1的机器上创建BrowserStackLocal连接并开始其测试执行。 测试工程师2在上午10:10运行测试:如果此BrowserStackLocal连接使用相同的密钥,它将断开测试工程师1机器上已运行的上一个会话,并启动测试工程师2机器上的本地连接。这可能导致测试工程师1基于所实现的错误处理逻辑运行的测试超时或终止。 按顺序运行测试时,不会影响任何测试,因为不会出现上述场景 为了避免这种情况,请确保在启动BrowserStackLocal时使用LocalIdentifier参数 如果使用命令行启动二进制文件,请使用以下命令: Mac: 窗口:
BrowserStackLocal.exe --key ACCESS_KEY --local-identifier RandomString
在测试脚本中,请添加以下功能
'browserstack.localIdentifier':'RandomString'
这将使您的desiredCapabilities块如下所示:
desiredCapabilities: {
'browserstack.user': "bla",
'browserstack.key': "bla",
'browserstack.local': true,
'browserstack.localIdentifier':'RandomString'
}
该随机字符串对于每个测试工程师都是唯一的,以确保他们的测试连接不会重叠或影响其他工程师的连接
desiredCapabilities: {
'browserstack.user': "bla",
'browserstack.key': "bla",
'browserstack.local': true,
'browserstack.localIdentifier':'RandomString'
}