npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wdio-fefanf-html-reporter

v0.0.8

Published

A WebdriverIO plugin. Create a basic HTML formatted report

Downloads

36

Readme

wdio-fefanf-html-reporter

A reporter for webdriver.io which generates a HTML report. This project is a fork of @rpii/wdio-html-reporter, which was itself a fork of a reporter I had previously created wdio-html-format-reporter

Installation

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

{
  "devDependencies": {
    "wdio-fefanf-html-reporter": "~0.0.1"
  }
}

Or, you can simply do it with:

npm install wdio-fefanf-html-reporter --save-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 'wdio-fefanf-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 use the template override option, can point to your own file in the test project:
            // templateFilename: path.resolve(__dirname, '../src/wdio-fefanf-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',
            
            // to use the template override option, can point to your own file in the test project:
            // templateFilename: path.resolve(__dirname, '../src/wdio-fefanf-html-reporter-alt-template.hbs')
        });
        reportAggregator.clean() ;

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

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

InnerStep results

This is a feature tied in the the wdio-fefanf-boilerplate project. One thing that I missed about Jest was the jest-each capability. That can now be achieved with mdTableToJson. The results from those tests can be displayed using this reporter doing the following:

Then(/^I check the input validation on the email$/, async () => {
  const scenarios = mdTableToJson(`
  | email            | errorMessage           | desc                                           |
  | ---------------- | ---------------------- | ---------------------------------------------- |
  |                  | Invalid email address. | empty field                                    |
  | asdf             | Invalid email address. | incomplete email address                       |
  | test@gmail       | Invalid email address. | incomplete email address                       |
  | test()@gmail.com | Invalid email address. | invalid email chars                            |
  | @gmail.com       | Invalid email address. | incomplete email address                       |
  | @gmail.com       | Invalid email address! | Expected failure due to incorrect errorMessage |
  `);

  for (let i = 0; i < scenarios.length; i += 1) {
    const { email, errorMessage, desc } = scenarios[i];
    await Steps.iTypeInto('emailCreateField', email);
    await Steps.iClickOn('createAccountButton');

    await Steps.iShouldSee('createAccountError');
    try {
      await Steps.textShouldContain('createAccountError', errorMessage);
    } catch (e) {
      process.emit('test:innerStepFail', `I check the input validation on the email :: ${email} :: ${desc}`);
      throw e;
    }
    process.emit('test:innerStepPass', `I check the input validation on the email :: ${email} :: ${desc}`);
  }
});

mdTableToJson Screenshot

Sample Output:

Report Screenshot