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

Cannot attach non string data to report #249

Closed
struankl opened this issue Sep 19, 2014 · 8 comments
Closed

Cannot attach non string data to report #249

struankl opened this issue Sep 19, 2014 · 8 comments

Comments

@struankl
Copy link

I think because of the fix for #233 the scenario.attach now only supports string data. If you try to pass it any other type it will have toString() called on it (previously toString('base64')) and if you try to pass data which is already base64 encoded then it gets it gets based64 encoded again at the formatting stage in the json formatter. @simondean mentioning you as instructed.

@simondean
Copy link
Contributor

Hi @struankl. The base64 encoding of everything is by design and follows the way attachments work in other Cucumber ports. You should be able to attach an image by passing it in as a Buffer or a Stream if you're using node.js. See #225 for some examples. Are you using node.js or running cucumber-js in a browser?

@simondean
Copy link
Contributor

Hi @struankl, see my comment above. Also there's some executable examples in https://github.com/cucumber/cucumber-js/blob/master/features/attachments.feature

@struankl
Copy link
Author

Thanks @simondean, I had tried this, but toString() gets called on the buffer, which corrupts any binary data. I think the examples you've linked to only work because they actually attach the string 'data', not real image data.

@struankl
Copy link
Author

Sorry, should have said, I'm running through node.js

@jlin412
Copy link

jlin412 commented Dec 17, 2014

@struankl
I have a workaround for similar. Maybe it will fix your issue:

      browser.takeScreenshot().then(function (png) {
        var fs = require('fs');

        //var base64Image = new Buffer(png, 'binary').toString('base64');
        var decodedImage = new Buffer(png, 'base64').toString('binary');

        scenario.attach(decodedImage, 'image/png');
      });

@struankl
Copy link
Author

struankl commented Jan 5, 2015

Thanks @jlin412 that worked for me.

@jbpros jbpros added this to the major features milestone Jun 9, 2015
@jbpros jbpros removed this from the major features milestone Oct 10, 2015
@jbpros
Copy link
Member

jbpros commented Oct 10, 2015

Seems to be ok now? Please reopen if needed.

@jbpros jbpros closed this as completed Oct 10, 2015
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants