我想压缩我的测试结果文件夹,并有一个方法来做同样的事情,但我 希望这个方法在onComplete函数之后执行,就像我一样 在onComplete函数中生成HTML报告,如果我有两者 onComplete函数中的方法,正在创建压缩文件夹 但是有0 KB,我想这是因为它在之前压缩了文件夹 报告生成。如何在onComplete之后执行方法 功能
onComplete: function () {
// Log any browser console errors that have not been logged in specs
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
platform = caps.get('platform');
var HTMLReport = require('protractor-html-reporter-2');
testConfig = {
reportTitle: 'E2E Test Summary Report',
outputPath: './build/test/results/E2E_Test_Summary_Report',
outputFilename: 'e2e_TestResult_'+datetime,
screenshotPath: './build/test/results/E2E_Test_Summary_Report/screenshots',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: true,
screenshotsOnlyOnFailure: true,
browserPrefix: true
};
new HTMLReport().from('./build/test/results/e2e-results.xml', testConfig);
});
zipE2EReport();
},
var zipE2EReport = function zipE2EReport() {
var output = fs1.createWriteStream('build/test/results/E2E_Test_Summary_Report.zip');
var archive = archiver('zip');
output.on('close', function () {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
//archive.bulk([
// { expand: true, cwd: 'src', src:'build/test/results/E2E_Test_Summary_Report'}
//]);
archive.directory('build/test/results/E2E_Test_Summary_Report', 'E2E_Test_Summary_Report');
archive.finalize();
};
Any help would be greatly appreciated.
Thanks in advance.
答案 0 :(得分:0)
一个简单的解决方案是将zip函数移动到生成HTML报告的then
链中,请参阅下面的代码示例:
capsPromise.then(function (caps) {
.....
return new HTMLReport().from('./build/test/results/e2e-results.xml', testConfig);
}).then(function(){
// move the zip function into the next `then`.
return zipE2EReport();
});