Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshots are broken in the html report in the recent versions of cucumber #2458

Closed
singhm13-nih opened this issue Dec 20, 2024 · 3 comments
Labels
❓ question Consider using support forums: https://cucumber.io/tools/cucumber-open/support

Comments

@singhm13-nih
Copy link

singhm13-nih commented Dec 20, 2024

👓 What did you see?

i'm using cucumber-js with nightwatch. I recently upgraded cucumber version from 8.11.1 --> 11.1.1. After upgrading I noticed the attached screenshots in the html report appears as broken image. I didn't change any code other than upgrading the dependency version. I downgraded to the version 8.11.1 and screenshot attachments are working fine. I'm not sure from what version it is broken as I tried few recent version and it showing the broken image in the report. Adding the piece of code, that I'm using:

await browser.saveScreenshot(filePath);

if(attachToReport) {
    const screenshotData = fs.readFileSync(filePath, {encoding: 'base64'});
    this.attach(screenshotData, 'image/png'); // Attach screenshot to the JSON output
}

✅ What did you expect to see?

Screenshot attachment should not be corrupted when attaching to the report

📦 Which tool/library version are you using?

node v20.12.2
cucumber 11.1.1
nightwatch 3.7.0

🔬 How could we reproduce it?

  1. setup basic project with nightwatch and cucumber
  2. Attach the screenshot using the code snippet( added in the description)
  3. Generate html report from cucumber json

📚 Any additional context?

No response

@davidjgoss
Copy link
Contributor

Thanks for raising @singhm13-nih.

Reading between the lines here, I think you're using a third-party HTML reporter that reads the JSON formatter output?

We made a change in 10.0.0 to how the JSON formatter treats string attachment content:

Previously, string attachments were included as plain text in the JSON formatter output, where other attachments were Base64 encoded. This meant for consumers, it was ambiguous whether any attachment was Base64 encoded or not. Now, all attachments are Base64 encoded regardless of how they were initially attached.

So your attachment which is already base64-encoded gets encoded again. To avoid this you can specify that it's already bade64-encoded by prefixing the MIME type, like this:

await browser.saveScreenshot(filePath);

if(attachToReport) {
    const screenshotData = fs.readFileSync(filePath, {encoding: 'base64'});
    this.attach(screenshotData, 'base64:image/png'); // Attach screenshot to the JSON output
}

@davidjgoss davidjgoss added the ❓ question Consider using support forums: https://cucumber.io/tools/cucumber-open/support label Jan 7, 2025
@shubhamkgupta14
Copy link

In my case this.attach() method is not working.
Could anyone help?

Image

@vitalets
Copy link

In my case this.attach() method is not working.
Could anyone help?

You should use regular function, not arrow. Have a look on this.

@davidjgoss davidjgoss closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Consider using support forums: https://cucumber.io/tools/cucumber-open/support
Projects
None yet
Development

No branches or pull requests

4 participants