这是我的conf.js文件。
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest : '/opt/src/protractor/results/',
filename : 'index.html',
showSummary : true,
showQuickLinks : true,
showConfiguration : true,
cleanDestination : true,
ignoreSkippedSpecs : false,
reportOnlyFailedSpecs : false,
captureOnlyFailedSpecs : true,
});
exports.config = {
...
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
onPrepare: function () {
reporter.dest = '/opt/src/protractor/results/' + browser.params.directory + '/';
jasmine.getEnv().addReporter(reporter);
我想通过传递参数来动态更改目标目录: 例如:
protractor conf.js --suite=MySuiteName --browser.params.directory=MyDirectory
所有报告均在/opt/src/protractor/results/
而非/opt/src/protractor/results/MyDirectory
为什么我无法更改目标目录?
提前致谢。 :)
答案 0 :(得分:0)
在protractor-jasmine2-screenshot-reporter
工具内部,只有在调用options.dest
时,才能通过传入的options
new HtmlScreenshotReporter(options)
读取目标文件夹。
因此,在生成报告文件时,更改reporter.dest
不会更改目标文件夹
请尝试以下代码:(延迟到onPrepare
中的init报告实例,您可以在其中获取CLI参数的值:--browser.params.directory
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reportOpts = {
dest : '/opt/src/protractor/results/',
filename : 'index.html',
showSummary : true,
showQuickLinks : true,
showConfiguration : true,
cleanDestination : true,
ignoreSkippedSpecs : false,
reportOnlyFailedSpecs : false,
captureOnlyFailedSpecs : true,
};
var reporter;
exports.config = {
onPrepare: function () {
// change reporter destination
reportOpts.dest = '/opt/src/protractor/results/' + browser.params.directory + '/';
// delay init reporter instance in onPrepare(), but beforelaunch()
reporter = new HtmlScreenshotReporter(reportOpts);
reporter.beforeLaunch(function(){
jasmine.getEnv().addReporter(reporter);
});
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};