I noticed that embedding images in cucumber/selenium html reports was
done in png. Since I’ve many features to test with screenshots, I
investigated how to make jpeg files instead and embed them. Main
target was to save disk space.
One major difficulty was to figure out why the converted image was
pink-ish. I understood later on that in java you need to convert the
image to RGB.
I’ve not fully worked out in jruby how to bypass local file creation
(here called ‘xshot.jpg’), but here’s the code. Someone might share
img = @browser.screenshot_as(:base64)
rgbimage = BufferedImage.new(pngimage.width, pngimage.height,
rgbimage.getGraphics().drawImage(pngimage, 0, 0, nil)
ImageIO.write(rgbimage, “jpeg”, Java::JavaIo::File.new(‘xshot.jpg’))
xshot = File.open(‘xshot.jpg’,‘rb’)
img = Base64.encode64 xshot.read
This code can be put in your ‘env.rb’, and later on you can call
‘xhost’ in your steps as you need them.
I’ve noticed the screenshots are above the gherkin lines in the html
report: is this normal ?