我正在从命令npm run e2e
我想要一种方法,这样如果我通过npm run e2e firefox
,那么我的测试将在Firefox浏览器上执行。
或者如果我运行npm run e2e chrome
,那么它应该在chrome上运行
如果我同时传递npm run e2e firefox chrome
,那么我的测试应该同时在浏览器上运行。
是否可以参数化量角器配置文件?
同样,如果我可以通过命令传递测试套件名称,它应该只在该特定测试套件下执行测试。
这是我的配置文件,这就是我想要实现的目标:
`//var HtmlReporter = require('protractor-html-screenshot-reporter');
exports.config = {
allScriptsTimeout: 30000,
//Add parameters for browser names
params:{
pass: {
browserName : 'chrome',
testSuitName : 'e2e/TestSuites/_BVT/*.js',
}
},
suites: {
//Define here List of Sanity Test Scenarios:
BVT : testSuitName,
},
// configure multiple browsers to run tests
multiCapabilities: [
shardTestFiles: true,
maxInstances: 2
{'browserName': browserName}
],
baseUrl: 'http://mytestUrl/',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'tests/test-results',
filePrefix: browserName + '-xmloutput',
modifySuiteName: function(generatedSuiteName, suite) {
return browserName + '.' + generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
},
resultJsonOutputFile: 'tests/test-results/output.json'
};`
对此有任何帮助表示感谢 提前致谢。
答案 0 :(得分:2)
我知道这篇文章现在有点老了,但是这个解决方案可以帮助有类似问题的人。
使用多个配置文件,每个浏览器类型一个,设置基本配置文件,并要求每个配置文件,然后为每个配置文件创建一个npm脚本。不需要参数,一切都很好。
所以基本配置(称为“protractor_base.js”)看起来像:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
rootElement: '[ng-app]',
allScriptsTimeout: 60000,
framework: 'jasmine',
specs: ['example-spec.js']
};
然后你的其他配置(即“protractor_chrome.conf.js”)看起来像:
protractor = require('./protractor_base.js');
var config = protractor.config;
config.capabilities: {
'browserName': 'chrome'
};
exports.config = config;
然后,您可以指定多浏览器配置,只需指定Chrome浏览器配置等
答案 1 :(得分:1)
--capabilities.chromeOptions.args=headless --capabilities.chromeOptions.args=disable-gpu --capabilities.chromeOptions.args=window-size=1200,600
上面的代码应该对您有用。
答案 2 :(得分:0)
我一直在寻找从命令行传递参数到量角器配置文件,并找到了一种方法:
npm run e2e -- --baseUrl=http://testurl:8080 --suite=suite_name_defined_in_config --capabilities.browserName=browser_Name
我的npm package.json:
"e2e": "protractor tests/protractor-conf.js",
和配置文件包含:
suites: {
BVT: 'e2e/TestSuites/_BVT/*.js',
Full: 'e2e/TestSuites/Full/**/*.js',
},
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8080/',