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

Decode base64-encoded Text Attachments #308

Merged
merged 2 commits into from
Jan 15, 2024
Merged

Conversation

mschluer
Copy link
Contributor

Since Cucumber 10, all Text Attachments are as well Base64 encoded, which currently makes them unreadable in the HTML-Reports.

This fix was created by @lerhum and @WasiqB.
As my customer needs this piece of code, I fixed the findings as described.
All Credits go the the creators, I just want to help speeden up things :)

Original Text

linked to #298

Describe the bug
In the JSON formatter output of multiple-cucumber-html-reporter, all attachments, including those initially attached as plain text strings, are now Base64 encoded. This uniform encoding approach leads to ambiguity for consumers of the report, as they cannot distinguish whether an attachment was originally a plain text string or a different file format.

To Reproduce
Steps to reproduce the behavior:

just generate a report based on cucumber 10.0.1 with some attachement (json/ text / image)

Expected behavior
The expected behavior was that string attachments would remain as plain text in the JSON formatter output, while other types of attachments would be Base64 encoded. This distinction would enable consumers to easily identify the nature of the attachments without additional processing.

Additional context
To resolve this issue, a decoding mechanism such as atob(embedding.data); should be implemented to correctly decode Base64 attachments before passing them to the report. This would ensure that plain text attachments maintain their original format in the JSON output.

@WasiqB
Copy link
Owner

WasiqB commented Jan 15, 2024

Hi @mschluer ,

Thanks for opening the PR.

Kindly look into the test failure, once that's fixed, we are good to merge.

@mschluer
Copy link
Contributor Author

It should work now, yet I would recommend to adjust the test data sooner or later

@WasiqB WasiqB merged commit c1278c6 into WasiqB:main Jan 15, 2024
1 check passed
@vitecz
Copy link

vitecz commented Jan 17, 2024

@mschluer hi, with the latest update I see the issue when there is an embeddings with "text/plain" mime type, in the cucumber html report there is base64 mess.
image
image

Is there a way to fix that e.g. through configuration

@mschluer
Copy link
Contributor Author

mschluer commented Jan 17, 2024

Hey,
which Cucumber-Version are you using?

With Cucumber 10 they decided to base64 encode text as well - unlike what they themselves state in their specification. Frankly, I did not yet fully understand their decision.
Upgrading to the most recent version of Cucumber should solve your Problem.

Reference: "Ensure attached string literals are base64-encoded in JSON reports (cucumber/cucumber-js#2260)" https:/cucumber/cucumber-js/releases/tag/v10.0.0

@vitecz
Copy link

vitecz commented Jan 17, 2024

@mschluer I use latest "wdio-cucumberjs-json-reporter" seems like this lib has no support of the change. So i need to convert any attach to base64 I assume and\or wait for the lib to support this.

I've tested this and seems everything works fine now
await cucumberJson.attach(Buffer.from('Scenario Start Time: ' + new Date().toISOString()).toString("base64"), 'text/plain');
Thanks.

@vitecz
Copy link

vitecz commented Jan 17, 2024

@WasiqB Sorry for being annoying. Seems like there is an issue when attaching "application/json" data type.
So now in my framework I encode everything into base64. JSON as well. But in the html cucumber report there is buffer array instead of JSON
image
image

I notice that this statement is never be true so the JSON will not be parsed and that's why the result is not JSON:
image
image
image
And obviously can not be stringified here:
image

If to revert this statement or remove, then the JSON is properly parsed:
image
image

Am i doing something wrong or there is an issue and the statement must be removed\reverted

@vitecz
Copy link

vitecz commented Jan 22, 2024

@WasiqB Hello. Any suggestion on the topic above? Appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants