JSON HTML Reporter Reporter
wdio-json-html-reporter is a 3rd party package, for more information please see GitHub | npm
This is a custom WebDriverIO reporter that generates detailed JSON reports during test execution and provides a portable HTML report generator to visualize your test results. It logs timestamps, execution metadata, and can capture screenshots on demand. The package follows the WebDriverIO convention for reporters and is published as an npm package under the name wdio-json-html-reporter.
⚡️ Dual Compatibility: CommonJS and ESM
This package works in both CommonJS (require) and ES Module (import) projects.
For CommonJS (require):
const { JSONReporter, HTMLReportGenerator } = require('wdio-json-html-reporter');
For ESM (import):
import { JSONReporter, HTMLReportGenerator } from 'wdio-json-html-reporter';
Table of Contents
- Overview
- Features
- Installation
- CLI Usage
- History Option and Aggregated History Generation
- Screenshots
Overview
WDIO JSON HTML REPORTER provides two main components:
- JSONReporter: A custom reporter that extends the WebDriverIO reporter interface to collect test events and generate a JSON file with metadata, test results, and (optionally) screenshots.
- HTMLReportGenerator: A utility to convert multiple JSON report files into a comprehensive HTML report with interactive charts, filtering, and export functionality. In addition, the report generator now supports an optional history file to display historical execution data if available. When no history data is provided, the report omits the historical section and shows only the Unique Errors.
These tools help you gain clear insights into your test runs, which is essential for debugging and continuous integration.
Features
- JSON Reporting: Detailed report with timestamps, suite names, test results, errors, and optional screenshots.
- HTML Reporting: Converts JSON reports into a portable HTML report with a dashboard, charts, detailed test report, and filtering capabilities.
- Export to Excel: The detailed test report can be exported to an Excel file.
- Screenshot Support: Capture screenshots for failed tests (or all tests) based on your configuration.
- Execution Metadata: Logs browser information, execution start/end times, and overall duration.
- Historical Execution (Optional): Provide a history JSON file to include historical execution data by suite. If no historical data is provided, the report will automatically hide this section and display only the Unique Errors.
- Aggregated History Generation: The JSON reporter now includes an aggregated history generation feature. Using the static method
JSONReporter.generateAggregateHistory({ reportPaths, historyPath, maxHistory }), you can automatically scan all JSON report files (matching the patterntest-report-*.json) in your report directory, aggregate test results, and compute defect comparisons based on historical data. The aggregated history record is then appended to your history file and can be used by the HTML report generator to visualize trends over time.
Installation
To install the wdio-json-html-reporter package, follow these steps:
1. Install the package
Run the following command to install the package as a development dependency:
npm install --save-dev wdio-json-html-reporter
2. Verify installation
Ensure that the package has been installed correctly by running:
npm list wdio-json-html-reporter
If installed correctly, you should see an output similar to:
wdio-json-html-reporter@x.x.x
3. Update WebDriverIO Configuration
Modify your wdio.conf.js or wdio.conf.ts file to include the custom reporter:
import { JSONReporter, HTMLReportGenerator } from 'wdio-json-html-reporter';
export const config = {
reporters: [
[JSONReporter, { outputFile: './reports/test-results.json', screenshotOption: 'OnFailure' }], // Options: "No", "OnFailure", "Full"
],
onComplete: async function() {
const outputFilePath = './reports/test-report.html';
const jsonFolder = './reports'; // Directory where JSON reports are saved
// If you want to include historical data, specify the history JSON file path here.
const historyFile = './reports/history.json'; // Optional
// Optionally, generate aggregated history data before generating the HTML report.
// JSONReporter.generateAggregateHistory({ reportPaths: jsonFolder, historyPath: historyFile });
const reportGenerator = new HTMLReportGenerator(outputFilePath, historyFile);
await reportGenerator.convertJSONFolderToHTML(jsonFolder);
}
};