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

Supporting HTML tag in screenshot embeddings? #129

Closed
xywang68 opened this issue Jan 28, 2018 · 7 comments
Closed

Supporting HTML tag in screenshot embeddings? #129

xywang68 opened this issue Jan 28, 2018 · 7 comments

Comments

@xywang68
Copy link
Contributor

xywang68 commented Jan 28, 2018

In order to avoid a huge cucumber-result.json file, instead of embedding the screenshot image as base64 data, I want to attach a HTML tag string like <img>. I am able to attach the tag using scenario.attach() call, but the cucumber-html-reporter is not showing.
Am I not doing this correctly? Otherwise can this be supported?

Here is my code in hooks.js:
var html_tag = '<img src="pulpitrock.jpg" alt="Mountain View">'; scenario.attach(Buffer.from(html_tag, 'utf-8'), 'text/html');

Here is the cucumber result JSON after run:
"embeddings": [ { "data": "PGltZyBzcmM9InB1bHBpdHJvY2suanBnIiBhbHQ9Ik1vdW50YWluIFZpZXciPg==", "mime_type": "text/html" } ],
which the data can be base64 decoded back to the original html_tag string.

@xywang68
Copy link
Contributor Author

xywang68 commented Jan 28, 2018

Hi, I subsequently made a small update in the lib/reporter.js with the following code in bold and it seems to work as I have requested above:

if (embeddingType === 'text/plain' || embeddingType === 'text/html') {
var decoded = new Buffer(embedding.data, 'base64').toString('ascii');

if (!step.text) {
step.text = decoded;
} else {
step.text = step.text.concat('
' + embedding.data);
}
} else if (embeddingType === 'application/json') {

@xywang68
Copy link
Contributor Author

xywang68 commented Jan 29, 2018

Here is the git diff. If this looks OK to you I can submit a PR.

$ git diff lib/reporter.js
warning: LF will be replaced by CRLF in lib/reporter.js.
The file will have its original line endings in your working directory.
diff --git a/lib/reporter.js b/lib/reporter.js
index a4b7320..1318918 100755
--- a/lib/reporter.js
+++ b/lib/reporter.js
@@ -220,9 +220,11 @@ var generateReport = function (options) {
embeddingType = embedding.media.type;
}

- if (embeddingType === 'text/plain') {
+ if (embeddingType === 'text/plain' || embeddingType === 'text/html') {
+ var decoded = new Buffer(embedding.data, 'base64').toString('ascii');
+
if (!step.text) {
- step.text = embedding.data;
+ step.text = decoded;
} else {
step.text = step.text.concat('
' + embedding.data);
}

@gkushang
Copy link
Owner

gkushang commented Feb 2, 2018

@xywang68 thanks for looking into it. Please submit a PR

@xywang68
Copy link
Contributor Author

xywang68 commented Feb 2, 2018

@gkushang , I tried to submit a branch to your git but got access denied. Can you grant permission for me to submit a branch? Or is there another way you prefer me to do?

@gkushang
Copy link
Owner

gkushang commented Feb 2, 2018

Hi @xywang68 - You'd not need to push the branch to the Origin. Please fork a repository, and submit a PR from your forked.

@xywang68
Copy link
Contributor Author

xywang68 commented Feb 3, 2018

@gkushang, created PR#132.

@gkushang
Copy link
Owner

gkushang commented Feb 6, 2018

Thanks for the PR. All set!

@gkushang gkushang closed this as completed Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants