Last active
March 11, 2022 15:45
-
-
Save shapeshifta78/741e76ae3ec50ecb799178a7110f46c6 to your computer and use it in GitHub Desktop.
Codeceptjs allure and reportportal helper - adds videos to reports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const log = require('simple-node-logger').createSimpleLogger({}); | |
const { container, Helper } = require('codeceptjs'); | |
const allureCLI = require('allure-commandline'); | |
/** | |
* this plugin will add videos of failed tests generated by Playwright to the allure and reportportal reports | |
*/ | |
class ReportingHelper extends Helper { | |
async _attachVideo(test) { | |
const Playwright = container.helpers('Playwright'); | |
const allure = container.plugins('allure'); | |
const reportPortal = container.plugins('reportportal'); | |
if (Playwright) { | |
await Playwright.browserContext.close(); | |
const FORMAT = 'video/webm'; | |
const TITLE = 'Video of failed Test'; | |
const video = | |
(test.artifacts !== undefined && test.artifacts.video !== undefined && test.artifacts.video) || | |
(test._retriedTest !== undefined && | |
test._retriedTest.artifacts.video !== undefined && | |
test._retriedTest.artifacts.video); | |
if (video) { | |
log.info(`Attaching Video: ${video}`); | |
if (allure) { | |
allure.addAttachment(TITLE, fs.readFileSync(video), FORMAT); | |
} | |
if (reportPortal) { | |
reportPortal.addLog( | |
{ | |
level: 'debug', | |
message: TITLE, | |
}, | |
{ | |
name: TITLE, | |
type: FORMAT, | |
content: fs.readFileSync(video), | |
} | |
); | |
} | |
} | |
} | |
} | |
async _failed(test) { | |
await this._attachVideo(test); | |
} | |
// optional, I needed to generate static test reports | |
async _finishTest(test) { | |
const generation = allureCLI(['generate', 'output', '-o', 'output/allure-results', '--clean']); | |
generation.on('exit', function (exitCode) { | |
log.info('Allure generation is finished with code: ', exitCode); | |
log.info(`Results can be found here: ${process.cwd()}/output/allure-results`); | |
}); | |
} | |
} | |
module.exports = ReportingHelper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment