No way to attach video of failed test to allure report in afterTest hook
Describe the bug
From PW documentation:
Videos are saved upon browser context closure at the end of a test. If you create a browser context manually, make sure to await browserContext.close().
So, if we need to get video of failed test we should wait for browserContext to be closed.
The implementation for allure-legacy plugin is present below:
async _after() {
const Playwright = container.helpers('Playwright');
const allure = container.plugins('allure');
await Playwright.browserContext.close();
if (this.#artifacts.video) {
output.debug(`Attaching a video: ${this.#artifacts.video}`);
allure.addAttachment('Video', fs.readFileSync(this.#artifacts.video), 'video/webm');
}
allure.currentTest = null;
}
Tried this implementation for allure-codeceptjs plugin but faced with the problem that currentTest is equal to null when test finished (passed / failed). The step 'allure.addAttachment' copies video file to allure-results repository but don't update <%.result.json> file by adding one more attachment.
Expected result:
"attachments": [
{
"name": "Console errors",
"type": "text/plain",
"source": "40b3cb14-4fde-42cf-b871-0d4c3812884b-attachment.txt"
},
{
"name": "Main session - Last Seen Screenshot",
"type": "image/png",
"source": "c2ecc7ea-c805-4553-82ec-84a02260cd34-attachment.png"
},
{
"name": "Video",
"type": "video/webm",
"source": <path to video file.webm>
}
],
Actual result:
"attachments": [
{
"name": "Console errors",
"type": "text/plain",
"source": "40b3cb14-4fde-42cf-b871-0d4c3812884b-attachment.txt"
},
{
"name": "Main session - Last Seen Screenshot",
"type": "image/png",
"source": "c2ecc7ea-c805-4553-82ec-84a02260cd34-attachment.png"
}
],
Tried to add an entry about the video attachment and run 'allure serve' -> the video was present in the report.
To Reproduce Steps to reproduce the behavior:
- Create AllureVideoHelper in codeceptJS project:
const Helper = require('@codeceptjs/helper');
const { event, container, output } = require('codeceptjs');
const fs = require('fs');
class AllureVideoHelper extends Helper {
#artifacts;
/**
* Constructor
*
* @param {object} config - Helper config
*/
constructor(config) {
super(config);
event.dispatcher.on(event.test.started, (test) => {
this.#artifacts = test.artifacts;
});
}
/**
* After test execution close browser context and add video to Allure report
*
*/
async _after() {
const Playwright = container.helpers('Playwright');
const allure = container.plugins('allure');
await Playwright.browserContext.close();
if (this.#artifacts.video) {
output.debug(`Attaching a video: ${this.#artifacts.video}`);
allure.addAttachment('Video', fs.readFileSync(this.#artifacts.video), 'video/webm');
}
}
}
module.exports = AllureVideoHelper;
- Add
video: truein codeceptJS configuration file
Playwright: {
....
video: true,
....
},
- Run test with a failure
- Run
allure serve - Check if video present as attach in allure report
Expected result The video is present
Actual result The video is NOT present
Desktop (please complete the following information):
- OS: mac
- Browser chrome
- Version: doesn't matter
I have a similar issue with Cypress, code allure.attachment is not working when I put in hook afterEach
here is the sample code
afterEach(function () {
let path = Cypress.spec.absolute.split('/cypress/tests/')[0]
cy.readFile(`${path}/cypress/1.png`, null).then((file) => {
allure.step('Get screenshot', () => {
allure.attachment('fileName', file, "image/png");
});
});
This code will now show on the allure report.. Maybe someone can check it? or maybe you guys don't support this on this hook ?
@dimas-rymera support for Cypress hooks introduced in 3.0.0-beta.4, please give it a try
@dimas-rymera support for Cypress hooks introduced in 3.0.0-beta.4, please give it a try
@baev Do the fixes cover CodeceptJS hooks?
@lifanov-rza, we added support for beforeEach & afterEach CodeceptJS hooks; however, hook methods in helpers are not reported by CodeceptJS, so we're still figuring out how we should handle it.