diff --git a/cypress/fixtures/customReportData.json b/cypress/fixtures/customReportData.json new file mode 100644 index 000000000..cb09a1e39 --- /dev/null +++ b/cypress/fixtures/customReportData.json @@ -0,0 +1,11 @@ +{ + "customFooter": { + "PageFooter": "Custom footer for main page", + "Account": "

Custom for Account pages

", + "Device": "

Custom for Device pages

" + }, + "customMetadata": { + "Account": "SetupAccount1
SetupAccount2", + "Device": "SetupDevice1
SetupDevice2" + } +} diff --git a/cypress/fixtures/customReportData.md b/cypress/fixtures/customReportData.md new file mode 100644 index 000000000..a37297fa6 --- /dev/null +++ b/cypress/fixtures/customReportData.md @@ -0,0 +1,35 @@ +# Overview +We use a JSON structure to define `customFooter` and `customMetadata` for various pages within the report. This allows dynamic customization, ensuring that each page can have specific information and design elements as needed. + +## Loading the JSON Data +The JSON data will first be loaded from `configModule/fixtures/external/objects/customReportData.json`. If this file is not available in the configModule, the data will be loaded from the local JSON file located at `cypress/fixtures/customReportData.json`. + +## Fields +`customFooter` + Contains customizable HTML content for the footers of different modules. + +- #### PageFooter: + - Type: string + - Description: HTML content for the main page footer. + - Example: `

Main page footer:

` +- #### Account: + - Type: string + - Description: HTML content for the Account page footer. + - Example: `

Custom for Account pages

` + +`customMetadata` + Contains customizable HTML content for the metadata sections of different modules. + + +- #### Account: + - Type: string + - Description: HTML content for the Account page metadata. + - Example: `SetupAccount1
SetupAccount2` + +# Usage Notes +- The `customFooter` object defines HTML content for footers on various pages. +- The `customMetadata` object defines HTML content for metadata sections on various pages. +- Ensure that the HTML content is properly escaped to avoid any issues with rendering. + +# Additional Information +- The JSON structure can be extended to include additional pages by adding new keys based on the feature file names, to the customFooter and customMetadata objects as needed. diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 73d50bf94..960afef67 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -298,7 +298,14 @@ module.exports = async (on, config) => { jsonReport = readDataFromFile(filePath + fileName); } const reportProperties = {}; + let customReportData; + try { + customReportData = require('../fixtures/external/objects/customReportData.json'); + } catch (error) { + customReportData = require('../fixtures/customReportData.json'); + } reportProperties.isCombinedTestRun = process.env.CYPRESS_isCombinedTestRun; + reportProperties.customReportData = customReportData; // Add the report to the reportObj if (reportType === CONSTANTS.CUCUMBER) { reportObj.cucumberReport = jsonReport; diff --git a/cypress/plugins/localReportGenerator.js b/cypress/plugins/localReportGenerator.js index 8ddbbe18b..8f1c6ab16 100644 --- a/cypress/plugins/localReportGenerator.js +++ b/cypress/plugins/localReportGenerator.js @@ -28,6 +28,8 @@ const logger = require('../support/Logger')('localReportGenerator.js'); const rename = util.promisify(fs.rename); const readdir = util.promisify(fs.readdir); const mkdir = util.promisify(fs.mkdir); +const readFileAsync = util.promisify(fs.readFile); +const writeFileAsync = util.promisify(fs.writeFile); /** * Generates local reports for Mochawesome and Cucumber based on the provided report data. @@ -70,16 +72,28 @@ async function generateLocalReport(reportObj, jobId) { if (reportObj.cucumberReport && reportObj.cucumberReportFilePath) { // Move cucumber json to a separate directory and get the path const cucumberDir = await filterCucumberJson(reportObj.cucumberReportFilePath); - + let customReportData; + try { + customReportData = require('../fixtures/external/objects/customReportData.json'); + } catch (error) { + customReportData = require('../fixtures/customReportData.json'); + } // Configure cucumber report options reportEnv.jsonDir = cucumberDir; reportEnv.reportPath = `./reports/${jobId}/cucumber-html-report`; + const featuresDir = `./reports/${jobId}/cucumber-html-report/features`; + if (customReportData.customFooter) + reportEnv.pageFooter = customReportData.customFooter.PageFooter; // Generate the cucumber report await cucumberReportGenerator.generate(reportEnv); // Remove tags from the generated cucumber report removeTagsFromCukeHtml(reportEnv.reportPath + '/index.html'); + if (customReportData.customFooter) + await processFeaturesFiles(featuresDir, customReportData.customFooter, 'customFooter'); + if (customReportData.customMetadata) + await processFeaturesFiles(featuresDir, customReportData.customMetadata, 'customMetadata'); logger.info( `A local report has been generated and can be accessed at ./reports/${jobId}/cucumber-html-report/index.html`, @@ -165,4 +179,53 @@ function removeTagsFromCukeHtml(htmlReportPath) { } } +async function updateCustomData(filePath, newCustomData, flag) { + const data = await readFileAsync(filePath, 'utf8'); + let updatedData; + if (flag.includes('customFooter')) { + const regex = /