How to get XML and HTML report for all browsers in protractor?

222 Views Asked by At

I need to generate both Jnuit style XML and HTML report but for only 1 browser. How to get it for all browsers. Using XML creating HTML with help of protractor-html-reporter-2.

 
 jasmine.getEnv().addReporter(
   new jasmineReporters.JUnitXmlReporter({
     consolidateAll: true,
     savePath: './report/',
   })
 );
},
1

There are 1 best solutions below

0
Ashish Chamoli On

We can use Jasmine reporter to create XML report and then user HTML reporter to convert those XML to HTML. However HTML doesn't show results in prettier manner.

Suggestion: You can use Jasmine reporter to create JUnit style XML report and for HTML you may use Protractor beautiful reporter.

In OnPrepare() method in Protractor config:

browser.driver.manage().window().maximize();
browser.get(browserConfig.url);
// Getting browserName from config for File name
browser.getProcessedConfig().then(browser => {
  const browserName = browser.capabilities.browserName;
  const junitReporter = new jasmineReporters.JUnitXmlReporter({
    consolidateAll: true,
    savePath: 'testresults',
    filePrefix: `${browserName}.xmloutput`
  });
  jasmine.getEnv().addReporter(junitReporter);
});

jasmine.getEnv().addReporter(new htmlReporter(reporter).getJasmine2Reporter());

and for reporter

const reporter = new htmlReporter({
  baseDirectory: 'Execution_HTMLReports',
  // tslint:disable-next-line:typedef
  pathBuilder: function pathBuilder(spec, descriptions, results, capabilities) {
    // tslint:disable-next-line:one-variable-per-declaration
    const currentDate = new Date(),
      day = currentDate.getDate(),
      month = currentDate.getMonth() + 1,
      year = currentDate.getFullYear();

    const validDescriptions = descriptions.map(description => {
      return description.replace('/', '@');
    });

    return path.join(day + '-' + month + '-' + year, capabilities.get('browserName'), validDescriptions.join('-'));
  },
  docName: _env + '_test-report.html',
  screenshotsSubfolder: 'screenshotsOnFailure',
  takeScreenShotsOnlyForFailedSpecs: true,
  excludeSkippedSpecs: true,
  preserveDirectory: false,
  gatherBrowserLogs: true,
  jsonsSubfolder: 'jsonsmetadata',
  clientDefaults: {
    showTotalDurationIn: 'header',
    totalDurationFormat: 'h:m:s',
    columnSettings: {
      displaySessionId: false,
      inlineScreenshots: false
    }
  }
});