本文介绍了如何在所有测试完成后(而不是每个文件)制作分片量角器测试报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当分片测试(也就是并行运行测试;即:shardTestFiles: true)时,Protractor 不会在 所有 测试完成时报告结果,而是报告每个 文件完成后.

有人有解决办法吗?

我尝试使用带有钩子 teardown 的内联

我之前在 protractor-jasmine2-html-reporter 在使用 'shardTestFiles' 共享测试时不会合并所有测试的结果:conf 文件中为 true

When sharding tests (aka running tests in parallel; ie: shardTestFiles: true), instead of reporting results when all tests are finished, Protractor reports results for each file when finished.

Does anyone have a workaround for this?

I've tried using an inline plugin with hooks teardown and postTest, but neither alter this behavior (still per test file reporting). I've also tried setting up the reporter outside of onPrepare, as suggested here, but also, no joy.

I'm hoping for an easy solution... but it wouldn't surprise me to find that folks throw their results in a db... also an acceptable answer.

解决方案

I am afraid there is not a easy answer to this,as Protractor overwrites the report files when using any custom plugins. But the below two worked for me.Choose what suits you best

1) Tinker with 'index.js' of Jasmine2HtmlReporter to append file instead of PhantomJs overwrite its using

2) Generate unique HTML reports by configuring Jasmine2HTML reporter from onPrepare() function and consolidate all the reports later

SOLUTION 1: The current code base of Jasmine2HtmlReporter - index.js uses two functions - phantomWrite() & nodeWrite() to write data. Refer here

I have created a new function - appendwrite() to append instead of overwriting and have modified code to pickup this functionCheck out my github code forked out of protractor-jasmine2-html-reporter

function appendwrite(path, filename, text){ var fs = require("fs"); var nodejs_path = require("path"); require("mkdirp").sync(path); // make sure the path exists var filepath = nodejs_path.join(path, filename); fs.appendFileSync(filepath,text) return; }

And modify the self.writeFile function in 'node_modules/protractor-jasmine2-html-reporter/index.js' to pickup the new function try { appendwrite(path, filename, text); //phantomWrite(path, filename, text); return; } catch (e) { errors.push(' PhantomJs attempt: ' + e.message); } try { nodeWrite(path, filename, text); return; } catch (f) { errors.push(' NodeJS attempt: ' + f.message); }

And Comment the below code which cleans reports on new run so that you dont see any error cleanup error - CleanUpCode

    rmdir(self.savePath);

SOLUTION 2: Generate separate reports based on sessionID for parallel instances by configuring the Jasmine reporter in OnPrepare function

onPrepare: function() { return new Promise(function (fulfill, reject) { browser.getCapabilities().then(function (value) { reportName = value.get('webdriver.remote.sessionid') + '_' + value.get('browserName') + '_' + Math.floor(Math.random()*1E16); jasmine.getEnv().addReporter( new Jasmine2HtmlReporter({ savePath: 'target/', screenshotsFolder: 'images', consolidate: true, consolidateAll: true, filePrefix: reportName + ".html" }) ); fulfill(); }) }); },

Step 2: Consolidate the reports generated across parallel instances in afterLaunch() method after complete tests are done and all webdriver sessions are closed

afterLaunch: function afterLaunch() { var fs = require('fs'); var output = ''; fs.readdirSync('target/').forEach(function(file){ if(!(fs.lstatSync('target/' + file).isDirectory())) output = output + fs.readFileSync('target/' + file); }); fs.writeFileSync('target/ConsolidatedReport.html', output, 'utf8'); },

You will see reports generated something like below with one ConsolidatedReport alsoPS: Please ignore any typo and syntax errors. this is just to serve as an example and can be customized

I have answers this earlier at protractor-jasmine2-html-reporter doesn't consolidate results for all test when tests are shared using 'shardTestFiles': true in conf file

这篇关于如何在所有测试完成后(而不是每个文件)制作分片量角器测试报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:03