How to make a report on the treatment test after all tests have been completed (instead of each file)?

When performing drawing tests (for example, parallel parallel tests, i.e. shardTestFiles: true), instead of reporting the results, when all tests are completed, reports on the results of each file end.

Does anyone have a workaround for this?

I tried using the built-in plugin using hooks teardownand postTest, but none of these changes are test files). I also tried setting up the reporter outside onPrepare, as suggested here , but also without joy.

I hope for an easy solution ... but it wouldn't surprise me if people found their results in db ... is also an acceptable answer.

+4
source share
2 answers

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

1) Tinker with 'index.js' Jasmine2HtmlReporter to add a file instead of PhantomJs overwrites its use

2) Create unique HTML reports by setting up the Jasmine2HTML reporter from the onPrepare () function and consolidating all reports later

SOLUTION 1: The current Jasmine2HtmlReporter code base - index.jsuses two functions - phantomWrite()and nodeWrite()for writing data. Contact here

- appendwrite() , github, 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; }

self.writeFile 'node_modules/protractor-jasmine2-html-reporter/index.js', 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); }

, , - CleanUpCode

    rmdir(self.savePath);

2: sessionID , OnPrepare

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(); }) }); },

2: , afterLaunch() webdriver

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'); },

, - ConsolidatedReport PS: , .

enter image description here

protractor-jasmine2-html- , 'shardTestFiles': true conf

+4

2- > 1. html- filePrefix fileNamePrefix, :

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,
                        fileNamePrefix: reportName + ".html"
                    })
                );
                fulfill();
            })
        });
    },
0

Source: https://habr.com/ru/post/1654618/


All Articles