Skip to main content

Html-Reporter API

Overview

Html-reporter adds an htmlReporter object to the testplane object with its own API.

NameTypeDescription
eventsObjectA list of events to subscribe to.
extraItemsObjectAdditional elements to be added to the burger menu of the report.
imagesSaverObjectInterface for saving images to the user's storage.
reportsSaverObjectInterface for saving sqlite databases to the user's storage.
addExtraItemMethodAdds an additional item to the burger menu of the report.
downloadDatabasesMethodDownloads all databases from the given files of the type databaseUrls.json.
mergeDatabasesMethodMerges all given databases and saves the final report on the specified path.
getTestsTreeFromDatabaseMethodReturns the test tree from the passed database.

events

A list of events to subscribe to.

For more information, see the section "Events".

extraItems

Additional elements to be added to the burger menu of the report.

To add elements, use the addExtraItem method.

imagesSaver

Interface for saving images to the user's storage.

Usage example

const MyStorage = require("my-storage");
const myStorage = new MyStorage();

module.exports = (testplane, opts) => {
testplane.on(testplane.events.INIT, async () => {
testplane.htmlReporter.imagesSaver = {
/**
* Save the image to a custom storage.
* The function can be either asynchronous or synchronous.
* The function should return the path or URL to the saved image.
* @property {String} localFilePath – the path to the image on the file system
* @param {Object} options
* @param {String} options.destPath – the path to the image in the html-report
* @param {String} options.reportDir - path to the html-report folder
* @returns {String} the path or URL to the image
*/
saveImg: async (localFilePath, options) => {
const { destPath, reportDir } = options;
const imageUrl = await myStorage.save(localFilePath, destPath, reportDir);

// ...

return imageUrl;
},
};
});
};

reportsSaver

Interface for saving sqlite databases to the user's storage.

Usage example

const MyStorage = require("my-storage");
const myStorage = new MyStorage();

module.exports = (testplane, opts) => {
testplane.on(testplane.events.INIT, async () => {
testplane.htmlReporter.reportsSaver = {
/**
* Save sqlite database to user storage.
* The function can be either asynchronous or synchronous.
* The function should return the path or URL to the saved sqlite database.
* @property {String} localFilePath – the path to the sqlite database on the file system
* @param {Object} options
* @param {String} options.destPath – the path to the sqlite database in the html-report
* @param {String} options.reportDir - path to the html-report folder
* @returns {String} the path or URL to the sqlite database
*/
saveReportData: async (localFilePath, options) => {
const { destPath, reportDir } = options;
const dbUrl = await myStorage.save(localFilePath, destPath, reportDir);

// ...

return dbUrl;
},
};
});
};

addExtraItem

Adds an additional item to the burger menu of the report.

Example of a call

testplane.htmlReporter.addExtraItem(caption, url);

Call parameters

All parameters are required.

Parameter nameTypeDescription
captionStringThe name of the item to add to the burger menu.
urlStringThe URL to which the menu item to be added will link.

downloadDatabases

Downloads all databases from the given files of the type databaseUrls.json.

Example of a call

const dbPaths = await testplane.htmlReporter.downloadDatabases([".databaseUrls.json"], {
pluginConfig,
});

Call parameters

The function takes 2 arguments—a list of paths to the files databaseUrls.json in the form of an array of strings and an object with the key pluginConfig, in the value of which the plugin config is stored.

The function returns a list of paths to saved databases.

mergeDatabases

Merges all given databases and saves the final report on the specified path.

Example of a call

await testplane.htmlReporter.mergeDatabases(srcDbPaths, path);

Call parameters

Parameter nameTypeDescription
srcDbPathsString[]Paths to databases.
pathStringThe path where the resulting database will be saved.

getTestsTreeFromDatabase

Returns the test tree from the passed database.

Example of a call

const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);

Call parameters

The function takes one argument—the path to the database with the result of the tests run.

Usage example

function getSuccessTestRunIds({ testplane, mergedDbPath }) {
const dbTree = testplane.htmlReporter.getTestsTreeFromDatabase(mergedDbPath);

const successTestRunIds = [];

for (const browserId of dbTree.browsers.allIds) {
const browser = dbTree.browsers.byId[browserId];
const lastResultId = _.last(browser.resultIds);
const lastResult = lastResultId && dbTree.results.byId[lastResultId];

if (!lastResult || lastResult.status !== SUCCESS) {
continue;
}

const testRunId = new URL(lastResult.suiteUrl).searchParams.get("testRunId");

if (!testRunId) {
continue;
}

successTestRunIds.push(testRunId);
}

return successTestRunIds;
}