Protractor-jasmine2-html reporter does not combine the results for all tests when sharing tests using the shardTestFiles: true command in the conf file

We recently set up our e2e tests on Jenkins, and soon we realized that we needed to use common test files: true parameters, since it takes a long time to fully launch a package, and we look at it for 9-10 hours daily. but when we configured below two parameters in the conf file. tests work fine, but the final report displays only the latest results of running the specification in the save path. consolidation of all parameters does not give complete reports.

find our data in the conf file. Any help would be appreciated.

Edit the conf file according to the solution provided by Aditya. please, help

   var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var log4js = require('log4js');
var params = process.argv;
var args = process.argv.slice(3);

exports.config = {
  //seleniumServerJar: './node_modules/gulp-protractor/node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  allScriptsTimeout: 100000,
  framework: 'jasmine2',

  onPrepare: function () {

    return new Promise(function(fulfill, reject) {
      browser.getCapabilities().then(function(value) {
        reportName = value.get(Math.random(8,2)) + '_' + value.get('browserName') + '_' + Math.floor(Math.random() * 1E16);
        jasmine.getEnv().addReporter(
          new Jasmine2HtmlReporter({
            //cleanDestination: false,
            savePath: __dirname+'/target',
            //docTitle: 'Web UI Test Report',
            screenshotsFolder: 'image',
            //takeScreenshots: true,
            takeScreenshotsOnlyOnFailures: true,
            consolidate: true,
            consolidateAll: true,
             preserveDirectory: true,
            //fixedScreenshotName: true,
            filePrefix: reportName + ".html"
          })
        );
        fulfill();
      });
    });

    // browser.manage().timeouts().implicitlyWait(11000);
    var width = 768;
    var height = 1366;
    browser.driver.manage().window().setSize(768, 1366);
    browser.ignoreSynchronization = false; 
  },

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

  },

  suites:{

    example:['./test/e2e/specs/**/*Spec.js',]
  },


  /*  capabilities: {
      'browserName': 'chrome'
    },*/

  multiCapabilities: [
    {
      'browserName': 'chrome'
    },
    {
      'browserName': 'firefox'
    }
  ],


  resultJsonOutputFile:'./results.json',

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 100000
  }
};
+2
4

"Jasmine2HtmlReporter", html, . , , , . ,

1) Tinker 'index.js' Jasmine2HtmlReporter PhantomJs

2) HTML, Jasmine2HTML onPrepare()

1: Jasmine2HtmlReporter - index.js - phantomWrite() nodeWrite() .

- 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

EDIT1: "sessionID", HTML, - webdriver, , , HTML

+2

, , BASE .

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');


exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['**-spec**.js'],

capabilities: {
    browserName: 'chrome',                                                      
    shardTestFiles: true,                                                        
    maxInstances: 2                                                             
},

onPrepare: function() {
    jasmine.getEnv().addReporter(
      new Jasmine2HtmlReporter({
        savePath: 'target/',
        screenshotsFolder: 'images',
        consolidate: true,
        consolidateAll: false  // false in my saved config - true in tut.
    })
  );
}
}

, ?

: , , Jasmine /, .

2: , , , . , :

capabilities: {
    browserName: 'chrome',                                                      
    shardTestFiles: true,                                                       
    maxInstances: **2**                                                             
},

HTML, 2. HTML /, . , 2 HTML, .

3: ...

cleanDestination: false,

, - , jasmine html , . github .

, , , - , , , , .

4: , HTML .

+1

Aditya . : var Jasmine2HtmlReporter = require ('protractor-jasmine2-html-reporter');

export.config = {   : "jasmine2",   seleniumAddress: 'http://localhost:4444/wd/hub',   /multiCapabilities: [       {           'browserName': 'chrome',           'shardTestFiles': true,           'maxInstances': 2,           chromeOptions: {               args: ['chrome.switches', '--disable-extensions']           }       },       {           'browserName': 'firefox'       }   ],/   :   {       'browserName': 'chrome',       'shardTestFiles': true,       'maxInstances': 2,       chromeOptions: {           args: ['chrome.switches', '--disable-extensions']       }   },   : {       loginpage: 'login.js',       addproduct: 'addproduct.js'   },   //specs: ['addproduct.js'],   jasmineNodeOpts: {       onComplete: null,       isVerbose: false,       includeStackTrace: true,       showColors: true,       defaultTimeoutInterval: 30000   },

onPrepare: function() {
    return new Promise(function(fulfill, reject) {
        browser.getCapabilities().then(function(value) {
            reportName = value.get(Math.random(8,2)) + '_' + value.get('browserName') + '_' + Math.floor(Math.random() * 1E16);
            jasmine.getEnv().addReporter(
                new Jasmine2HtmlReporter({
                    //cleanDestination: false,
                    savePath: 'target/',
                    //docTitle: 'Web UI Test Report',
                    screenshotsFolder: 'image',
                    //takeScreenshots: true,
                    //takeScreenshotsOnlyOnFailures: true,
                    consolidate: true,
                    consolidateAll: true,
                   // preserveDirectory: true,
                    //fixedScreenshotName: true,
                    filePrefix: reportName + ".html"
                })
            );
            fulfill();
        });
    });
},
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');
}

}

0
source

I used the solution below to create a unique folder with a unique timestamp. This will save the HTML report in a folder with a date stamp, instead, the Jasmin-2-html reporter will delete it.

var today = new Date();
   var timeStamp = today.getMonth() + 1 + '-' + today.getDate() + '-' + today.getFullYear() + '-' + 

today.getHours() + 'h-' + today.getMinutes() + 'm-' +today.getSeconds()+'s';

 jasmine.getEnv().addReporter(
            new Jasmine2HtmlReporter({
                savePath: './Reports/testResultsReport '+timeStamp,
                screenshotsFolder: 'screenPrints',
                takeScreenshots: true,
                takeScreenshotsOnlyOnFailures: true,
            })
        ); 

`

0
source

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


All Articles