@rpii/wdio-html-reporter
WebdriverIO report plugin. Create a basic HTML formatted report. compatible with webdriverio version 6
Last updated a month ago by rpii .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rpii/wdio-html-reporter 
SYNC missed versions from official npm registry.

wdio-html-reporter

A reporter for webdriver.io which generates a HTML report.

Compatible with webdriverio version 6, with a typescript type file.

This project is a fork of wdio-html-format-reporter That project has not been updated and doesnt work with the latest webdriverio 5.x or 6.x.

This project does. A pull request was submitted to that project, but it appears to be inactive. Due to name conflict issues, this package had to be put in my user namespace. it is now in npm.

This module has been tested with mocha and now cucumber. It works with both.

Installation

The easiest way is to keep the @rpii/wdio-html-reporter as a devDependency in your package.json:

{
  "devDependencies": {
    "@rpii/wdio-html-reporter": "~1.0.0"
  }
}

Or, you can simply do it with:

yarn add @rpii/wdio-html-reporter --dev

Configuration

The following code shows the default wdio test runner configuration. Just add an HtmlReporter object as another reporter to the reporters array. Syntax shown requires babel:

// wdio.conf.js
import { ReportAggregator, HtmlReporter} from '@rpii/wdio-html-reporter' ;
module.exports = {

  
  reporters: ['spec',
        [HtmlReporter, {
            debug: true,
            outputDir: './reports/html-reports/',
            filename: 'report.html',
            reportTitle: 'Test Report Title',
            
            //to show the report in a browser when done
            showInBrowser: true,

            //to turn on screenshots after every test
            useOnAfterCommandForScreenshot: false,

            // to use the template override option, can point to your own file in the test project:
            // templateFilename: path.resolve(__dirname, '../template/wdio-html-reporter-alt-template.hbs'),
            
            // to add custom template functions for your custom template:
            // templateFuncs: {
            //     addOne: (v) => {
            //         return v+1;
            //     },
            // },

            //to initialize the logger
            LOG: log4j.getLogger("default")
        }
        ]
    ]
    
 
};

Configuration Options:

To generate a master report for all suites

webdriver.io will call the reporter for each test suite. It does not aggregate the reports. To do this, add the following event handlers to your wdio.config.js

    onPrepare: function (config, capabilities) {

        let reportAggregator = new ReportAggregator({
            outputDir: './reports/html-reports/',
            filename: 'master-report.html',
            reportTitle: 'Master Report',
            browserName : browser.capabilities.browserName,
            // to use the template override option, can point to your own file in the test project:
            // templateFilename: path.resolve(__dirname, '../template/wdio-html-reporter-alt-template.hbs')
        });
        reportAggregator.clean() ;

        global.reportAggregator = reportAggregator;
    },
    
    onComplete: function(exitCode, config, capabilities, results) {
        (async () => {
            await global.reportAggregator.createReport();
        })();
    },
    

To use a logger for debugging

A new feature for developers is to add a log4js logger to see detailed debug output. See the test/reporter.spec.js for configuration options

To use a custom handlebars template for reports

Uncomment the templateFilename above, and in the ReportAggregator. You must provide an absolute path to the file you can modify the alt-template above if you wish The template must support all the constructs in the default template. You may add more or just change the formatting and css.

Add Message and Screenshots to the Html Report:

To show messages in the html report

Add the function below to your test code and call it when you want to output a message

    logMessage(message) {
        process.emit('test:log', message);
    }

To take Screenshots:

Add a function that you can call from anywhere in your test:

    takeScreenshot(message) {
        const timestamp = moment().format('YYYYMMDD-HHmmss.SSS');
        fs.ensureDirSync('reports/html-reports/screenshots/');
        const filepath = path.join('reports/html-reports/screenshots/', timestamp + '.png');
        this.browser.saveScreenshot(filepath);
        this.logMessage(message) ;
        process.emit('test:screenshot', filepath);
        return this;
    }

To take a screenshot after any test fails:

wdio.conf.js

    afterTest: function (test) {
        const path = require('path');
        const moment = require('moment');

        // if test passed, ignore, else take and save screenshot.
        if (test.passed) {
            return;
        }
        const timestamp = moment().format('YYYYMMDD-HHmmss.SSS');
        const filepath = path.join('reports/html-reports/screenshots/', timestamp + '.png');
        browser.saveScreenshot(filepath);
        process.emit('test:screenshot', filepath);
    },

To take a screenshot after each test completes:

Set the option useOnAfterCommandForScreenshot to true

This option is used if you are not using either of the screenshot options above.

Sample Output:

Report Screenshot

Current Tags

  • 6.0.4                                ...           latest (a month ago)

49 Versions

  • 6.0.4                                ...           a month ago
  • 6.0.3                                ...           a month ago
  • 6.0.2                                ...           a month ago
  • 6.0.1                                ...           2 months ago
  • 6.0.0                                ...           2 months ago
  • 1.0.4                                ...           2 months ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.0                                ...           2 months ago
  • 0.9.8                                ...           2 months ago
  • 0.9.7                                ...           2 months ago
  • 0.9.6                                ...           2 months ago
  • 0.9.5                                ...           2 months ago
  • 0.9.4                                ...           2 months ago
  • 0.9.3                                ...           2 months ago
  • 0.9.2                                ...           2 months ago
  • 0.9.1                                ...           2 months ago
  • 0.9.0                                ...           2 months ago
  • 0.8.9                                ...           2 months ago
  • 0.8.8                                ...           2 months ago
  • 0.8.7                                ...           2 months ago
  • 0.8.6                                ...           4 months ago
  • 0.8.5                                ...           4 months ago
  • 0.8.4                                ...           5 months ago
  • 0.8.3                                ...           5 months ago
  • 0.8.2                                ...           8 months ago
  • 0.8.1                                ...           8 months ago
  • 0.8.0                                ...           8 months ago
  • 0.7.9                                ...           9 months ago
  • 0.7.8                                ...           9 months ago
  • 0.7.7                                ...           10 months ago
  • 0.7.6                                ...           10 months ago
  • 0.7.5                                ...           10 months ago
  • 0.7.4                                ...           10 months ago
  • 0.7.3                                ...           a year ago
  • 0.7.2                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.6.6                                ...           a year ago
  • 0.6.5                                ...           a year ago
  • 0.6.4                                ...           a year ago
  • 0.6.3                                ...           a year ago
  • 0.6.1                                ...           a year ago
  • 0.6.0                                ...           a year ago
  • 0.5.4                                ...           a year ago
  • 0.5.3                                ...           a year ago
  • 0.5.2                                ...           a year ago
  • 0.5.1                                ...           a year ago
  • 0.5.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 111
Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |