Hey i facing an issue regarding taking screenshots and added to the cucumber-html reporter using playwright
And for me is a weird issue
So if i add status.PASSED it works is taking screenshots and also add video to report
The issue cames when i want to add only screenshots and videos on Status.FAILED
The report is generated but no screnshots are taken and no video attachment to the report
Hooks.ts
After(async function ({ pickle, result }) {
let videoPath: string;
let img: Buffer;
const path = `./test-result/trace/${pickle.id}.zip`;
if (result?.status == Status.FAILED) {
console.log("Test failed, taking screenshot and video...");
img = await pageFixture.page.screenshot({
path: `./test-result/screenshots/${pickle.name}.png`,
type: "png",
});
videoPath = await pageFixture.page.video().path();
}
await context.tracing.stop({ path: path });
// await pageFixture.page.close();
// await context.close();
if (result?.status == Status.FAILED) {
await this.attach(img, "image/png");
await this.attach(fs.readFileSync(videoPath), "video/webm");
const traceFileLink = `<a href="https://trace.playwright.dev/">Open ${path}</a>`;
await this.attach(`Trace file: ${traceFileLink}`, "text/html");
}
// Close the page and context after all operations are done
await pageFixture.page.close();
await context.close();
});
package.json
"scripts": {
"pretest": "npx ts-node src/helper/report/init.ts",
"test": "cross-env ENV=stage cucumber-js --config=config/cucumber.js test || echo "Test failed"",
"posttest": "npx ts-node src/helper/report/reporter.ts",
"test:failed": "cross-env ENV=stage cucumber-js @rerun.txt --format rerun:@rerun.txt"
},
cucumber.js
module.exports = {
default: {
tags: process.env.npm_config_TAGS || "",
formatOptions: {
snippetInterface: "async-await",
},
paths: ["src/test/features/"],
dryRun: false,
require: ["src/test/steps/*.ts", "src/hooks/hooks.ts"],
requireModule: ["ts-node/register"],
format: [
"progress-bar",
"html:test-result/cucumber-report.html",
"json:test-result/cucumber-report.json",
"rerun:@rerun.txt",
],
parallel: 0,
},
rerun: {
formatOptions: {
snippetInterface: "async-await",
},
dryRun: false,
require: ["src/test/steps/*.ts", "src/hooks/hooks.ts"],
requireModule: ["ts-node/register"],
format: [
"progress-bar",
"html:test-result/cucumber-report.html",
"json:test-result/cucumber-report.json",
"rerun:@rerun.txt",
],
parallel: 0,
},
};
When i change the status to PASSED the test take screen shots and passed in to the report
if (result?.status == Status.PASSED) {
console.log("Test failed, taking screenshot and video...");
img = await pageFixture.page.screenshot({
path: `./test-result/screenshots/${pickle.name}.png`,
type: "png",
});
videoPath = await pageFixture.page.video().path();
}
await context.tracing.stop({ path: path });
// await pageFixture.page.close();
// await context.close();
if (result?.status == Status.PASSED) {
await this.attach(img, "image/png");
await this.attach(fs.readFileSync(videoPath), "video/webm");
const traceFileLink = `<a href="https://trace.playwright.dev/">Open ${path}</a>`;
await this.attach(`Trace file: ${traceFileLink}`, "text/html");
}
Claudiu Cioaca is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.