mattheworiordan / capybara-screenshot

Automatically save screen shots when a Capybara scenario fails
MIT License
1.02k stars 168 forks source link

Mime-type for Cucumber 4+ doesn't include "base64" part #279

Closed andrii-rymar closed 2 years ago

andrii-rymar commented 3 years ago

For Cucumber 3 next code is used to embed screenshot: embed(encoded_img, 'image/png;base64', "Screenshot of the error")

For Cucumber 4+ screenshot is also embedded as Base64 but without explicitly specifying it: attach(encoded_img, 'image/png')

Omitting ;base64 part causes some reporting tools (like ReportPortal) to treat file incorrectly thus not adding images to the reports.

andrii-rymar commented 3 years ago

It appeared it also affects Cucumber Reports plugin for Jenkins - it's doesn't display image embedded into json report as base64.

markstanley-nps commented 3 years ago

I am seeing a related issue on cucumber (5.3.0) capybara-screenshot (1.0.25)

Running my tests with cucumber -f html -o <file>

However the fix above does not resolve the issue I am seeing

The cucumber attach code appears to always base64 encode the source and alter the media type (https://github.com/cucumber/cucumber-ruby/blob/master/lib/cucumber/formatter/message_builder.rb)

Attaching the non base 64 encoded image as below seems to fix my case

        if respond_to? :attach
          attach(image, 'image/png')
        else
          embed(encoded_img, 'image/png;base64', 'Screenshot of the error')
        end