common
common copied to clipboard
Attaching base64 encoded data - should cucumber decide by itself for re-encoding ?
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)
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
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?
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.
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.
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?
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.
This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.
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");
You can, and should, attach a byte array. Use OutputType.BYTES
.
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:
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
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
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.
Do we think this can be marked as closed now then @mpkorstanje / @davidjgoss
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.