Cucumber for non screenshot screenshots

Submitted by Google Cukes:

I experimented with several ways to save screenshots, but settled on a method that is built into watir-webdriver. There is no question which method I used, I can’t successfully embed a link to this image in the HTML report of the cucumber.

In c: \ ruby ​​\ cucumber \ project_name \ features \ support \ hooks.rb, I use:

After do |scenario| if scenario.failed? @browser.driver.save_screenshot("screenshot.png") embed("screenshot.png", "image/png") end end 

A link to the text “Screenshot” was added to the report, but the URL is the path to the project directory ("c:\ruby\cucumber\project_name") than the direct link to the file ("c:\ruby\cucumber\project_name\screenshot.png") . I tried several different image formats and direct paths using Dir.pwd with the same results every time.

What am I missing?

thanks

Windows XP Ruby 1.8.7 watir-webdriver (0.2.4) cucumber (0,10.3)

+3
source share
1 answer

Aslak:

Try the following:

 After do |scenario| if scenario.failed? encoded_img = @browser.driver.screenshot_as(:base64) embed("data:image/png;base64,#{encoded_img}",'image/png') end end 

Aslak

Adam:

Aslak was able to see the inline image in the file that I emailed to him, while I still couldn’t do it in IE 8. I tried it in Firefox 3.6 and the image will look as expected. Perhaps the problem was initially with the implementation method itself (or rather, my use), but using the Aslak base64 solution it only fails to work in the Internet Explorer browser.

Aslak:

I believe that Base64-encoded images in HTML pages [1] work in all decent browsers (sorry, IE is not one of them). However, it should IE: http://dean.edwards.name/weblog/2005/06/base64-ie/ (but maybe they broke it in IE8, or maybe it only works with gif, or maybe IE needs in a special base64, or maybe you should just ditch IE)

If you can read hucm cucumber reports with screenshots in IE it is really important for you, you could always write each image to disk:

  png = @browser.driver.screenshot_as(:png) path = (0..16).to_a.map{|a| rand(16).to_s(16)}.join + '.png' # Or use some GUID library to make a unique filename - scenario names are not guaranteed to be unique. File.open(path, 'wb') {|io| io.write(png)} embed(path, 'image/png') 

Obviously, you have to make sure that the relative path you pass for implementation is right (depending on where you write the html itself)

[1] http://en.wikipedia.org/wiki/Data_URI_scheme

HTH, Aslak

+3
source

Source: https://habr.com/ru/post/906596/


All Articles