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

Attaching base64 encoded data - should cucumber decide by itself for re-encoding ? #1116

Open
vincent-psarga opened this issue Jul 15, 2020 · 15 comments
Labels
⚡ enhancement Request for new functionality

Comments

@vincent-psarga
Copy link
Contributor

Summary

This is a follow up from cucumber-ruby#1443.

The user attaches a screenshot which is already encoded in base64. When we attach a file, we encode it once again as base64 which makes the file "unreadable" (well, we can still decode it twice, but that's not what we want).

I want to add a bit more intelligence to cucumber-ruby so when we detect that the file is encoded in base64, we do not try to encode it once again.

How does this work for cucumber-jvm and cucumber-js ?
Shall I add an example in the CCK to ensure that all version of cucumber do the same thing ?

Expected Behavior

Being smart :D

Possible Solution

  • test if the file is already encoded
  • add a CCK example

Steps to Reproduce (for bugs)

  1. see cucumber-ruby#1443
@vincent-psarga vincent-psarga added the ⚡ enhancement Request for new functionality label Jul 15, 2020
@vincent-psarga
Copy link
Contributor Author

note @mpkorstanje - I'm not really assigning you, I was more expecting a point of view for cucumber-jvm but I forgot this was an issue and not a PR :D

@mpkorstanje mpkorstanje removed their assignment Jul 15, 2020
@mpkorstanje
Copy link
Contributor

How does this work for cucumber-jvm

In Java you attach bytes.

The user attaches a screenshot which is already encoded in base64.

So.... don't do that and use bytes?

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jul 15, 2020

I want to add a bit more intelligence to cucumber-ruby so when we detect that the file is encoded in base64, we do not try to encode it once again.

You might have to introduce an extra method to attach file contents instead. I don't think this can be solved with smarts without some annoying edge cases.

@vincent-psarga
Copy link
Contributor Author

You might have to introduce an extra method to attach file contents instead. I don't think this can be solved with smarts without some annoying edge cases.

Something like attachBase64 would make sense I guess.

@aslakhellesoy
Copy link
Contributor

If a user attaches a base64 encoded string, they also specify the media type, for example:

attach(data, 'image/png')

In fake-cucumber we look at the data argument to determine whether the attached data is a string or binary data. (A Buffer or Stream.Readable is considered to be binary data).

See makeAttach

If it's a string, the content encoding is identity, which means we don't base64 encode it.

I think the problem is that in Ruby, binary data is represented as a string. So how do we determine whether or not to base64 encode a string?

There is a trick to this, and it's more a convention than a 100% failsafe approach. If data.encoding == Encoding::ASCII-8BIT then treat it as binary (and base64 encode it). Otherwise, consider it to be text and specify content encoding identity.

Makes sense?

@stale
Copy link

stale bot commented Oct 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the ⌛ stale Will soon be closed by stalebot unless there is activity label Oct 11, 2020
@stale
Copy link

stale bot commented Dec 15, 2020

This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.

@stale stale bot closed this as completed Dec 15, 2020
@aslakhellesoy aslakhellesoy reopened this Dec 18, 2020
@stale stale bot removed the ⌛ stale Will soon be closed by stalebot unless there is activity label Dec 18, 2020
@harihere
Copy link

harihere commented Dec 3, 2021

Any workaround for this issue ?

Not able to attach base 64 screenshots to cucumber reports.
io.cucumber - 6.9.1
Report - net.masterthought cucumber-reporting -5.6.1
Language -- Java

Example :

final String Screenshot =((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
SCENARIO.attach(Screenshot,"image/png","BASE64");

@mpkorstanje
Copy link
Contributor

You can, and should, attach a byte array. Use OutputType.BYTES.

@davidjgoss
Copy link
Contributor

fwiw in cucumber-js we handled it like this:

If you've already got a base64-encoded string, you can prefix your mime type with base64: to indicate this:

@harihere
Copy link

harihere commented Dec 3, 2021

You can, and should, attach a byte array. Use OutputType.BYTES.

Attaching as Byte array is working , how to attach a screenshot which is encoded into base 64 , so that screenshot files are not required while sharing the report

@harihere
Copy link

harihere commented Dec 3, 2021

fwiw in cucumber-js we handled it like this:

If you've already got a base64-encoded string, you can prefix your mime type with base64: to indicate this:

Yes tried in this way , still no good luck

@mpkorstanje
Copy link
Contributor

Attaching as Byte array is working , how to attach a screenshot which is encoded into base 64 , so that screenshot files are not required while sharing the report

Since the report is made by masterthought you should ask there.

@luke-hill
Copy link
Contributor

Do we think this can be marked as closed now then @mpkorstanje / @davidjgoss

@davidjgoss
Copy link
Contributor

I would say it lives in cucumber-ruby, given jvm doesn't have this issue and js has solved it in its own way. The original query was about how it works in other impls which is answered, so now it's a case of what - if anything - should be changed in ruby land.

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

No branches or pull requests

6 participants