common icon indicating copy to clipboard operation
common copied to clipboard

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

Open vincent-psarga opened this issue 4 years ago • 15 comments

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 avatar Jul 15 '20 08:07 vincent-psarga

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

vincent-psarga avatar Jul 15 '20 08:07 vincent-psarga

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 avatar Jul 15 '20 08:07 mpkorstanje

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.

mpkorstanje avatar Jul 15 '20 08:07 mpkorstanje

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.

vincent-psarga avatar Jul 15 '20 12:07 vincent-psarga

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?

aslakhellesoy avatar Aug 07 '20 11:08 aslakhellesoy

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[bot] avatar Oct 11 '20 23:10 stale[bot]

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

stale[bot] avatar Dec 15 '20 21:12 stale[bot]

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");

harihere avatar Dec 03 '21 08:12 harihere

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

mpkorstanje avatar Dec 03 '21 08:12 mpkorstanje

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:

davidjgoss avatar Dec 03 '21 08:12 davidjgoss

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 avatar Dec 03 '21 09:12 harihere

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

harihere avatar Dec 03 '21 09:12 harihere

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.

mpkorstanje avatar Dec 03 '21 09:12 mpkorstanje

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

luke-hill avatar Sep 05 '23 11:09 luke-hill

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.

davidjgoss avatar Sep 05 '23 11:09 davidjgoss