Skip to main content

Command Palette

Search for a command to run...

How to add screenshot on failures for allure reports for WebDriverIO using Typescript

How to add screenshot in allure reports on test failures

Updated
1 min read
How to add screenshot on failures for allure reports for WebDriverIO using Typescript

**How to add screenshot in allure reports on test failures ** Stack :

  • WebDriverIO

  • CucumberJS

  • TypeScript

This works with parallel test runs too.

WebdriverIO Allure Docs here

const allure = require('allure-commandline');
require('dotenv').config();

export const hooks = {
  afterStep: function (step, scenario, { error, duration, passed }, context) {
    if (error) {
      browser.saveScreenshot('results/allure-results/afterStepScreenshot.png');
    }
  },
  onComplete: async function () {
    const reportError = new Error('Could not generate Allure report');
    const generation = allure([
      'generate',
      'results/allure-results',
      '--clean',
      '--output',
      'results/allure-reports',
    ]);
    return new Promise<void>((resolve, reject) => {
      const generationTimeout = setTimeout(() => reject(reportError), 10000);

      generation.on('exit', function (exitCode) {
        clearTimeout(generationTimeout);

        if (exitCode !== 0) {
          return reject(reportError);
        }

        console.log('Allure report successfully generated');
        resolve();
      });
    });
  },
};

Testing

Part 4 of 6

Discover the power of testing in software development, from manual to automated techniques. Learn how to ensure quality and reliability, and explore the latest trends and best practices.

Up next

Unit tests in the serverless landscape

Unit tests in a server-less setup aka Lambdas and similar