用于未链接到屏幕截图的屏幕截图的 Cucumber 嵌入 [英] Cucumber embed for screenshots not linking to screenshot

查看:24
本文介绍了用于未链接到屏幕截图的屏幕截图的 Cucumber 嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cukes Google Group 交叉发布:

我尝试了多种保存屏幕截图的方法,但确定了内置于 watir-webdriver 的方法.不无论我使用哪种方法,我都无法成功嵌入Cucumber HTML 报告中指向此图像的链接.

在 c: ubycucumberproject_namefeaturessupporthooks.rb 中,我使用的是:

之后做 |scenario|如果scenario.failed?@browser.driver.save_screenshot("screenshot.png")嵌入(screenshot.png",图像/png")结尾结尾

一个带有文本屏幕截图"的链接已添加到报告中,但 URL 是项目目录路径 ("c: ubycucumberproject_name") 而不是而不是直接链接到文件 ("c: ubycucumberproject_namescreenshot.png").我尝试了许多不同的图像格式和使用 Dir.pwd 的直接路径每次都具有相同的结果.

我错过了什么?

谢谢

Windows XP红宝石 1.8.7水网驱动程序(0.2.4)黄瓜 (0.10.3)

解决方案

Aslak:

<块引用>

试试这个:

之后做 |scenario|如果scenario.failed?encoded_img = @browser.driver.screenshot_as(:base64)嵌入(数据:图像/png;base64,#{encoded_img}",'图像/png')结尾结尾

<块引用>

阿斯拉克

亚当:

<块引用>

Aslak 能够看​​到嵌入的我通过电子邮件发送给他的文件中的图像,虽然我仍然无法这样做IE 8.我在 Firefox 3.6 中尝试过并且图像按预期显示.问题最初可能是使用嵌入方法本身(或相反,我使用它),但使用Aslak 的 base64 解决方案只会失败在 Internet Explorer 中工作浏览器.

阿斯拉克:

<块引用>

我相信图像的 Base64 编码HTML 页面 [1] 可以正常工作浏览器(对不起,IE 不是其中之一他们).但是,它应该在IE:http://dean.edwards.name/weblog/2005/06/base64-即/(但也许他们在 IE8 中破坏了它,或者也许它只适用于 gif,或者也许 IE 需要一种特殊的base64 编码,或者你应该放弃 IE)

如果能够阅读黄瓜html在 IE 中带有屏幕截图的报告是对你来说真的很重要,你可以始终将每个图像写入磁盘:

 png = @browser.driver.screenshot_as(:png)路径 = (0..16).to_a.map{|a|rand(16).to_s(16)}.join + '.png' # 或者使用一些 GUID 库来创建一个唯一的文件名 - 场景名称不保证是唯一的.File.open(路径, 'wb') {|io|io.write(png)}嵌入(路径,图像/png")

<块引用>

显然,您必须确保您传递给嵌入的相对路径是对(取决于你写的地方html 本身)

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

HTH,阿斯拉克

Cross-posted from the Cukes Google Group:

I have experimented with a number of methods of saving screenshots, but settled on the method that is built into watir-webdriver. No matter which method I have used, I am not able to successfully embed a link to this image in the Cucumber HTML report.

In c: ubycucumberproject_namefeaturessupporthooks.rb, I'm using:

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

A link with text "Screenshot" IS added to the report, but the URL is the project directory path ("c: ubycucumberproject_name") rather than a direct link to the file ("c: ubycucumberproject_namescreenshot.png"). I have tried a number of different image formats and direct paths using Dir.pwd with the same results each time.

What am I missing?

Thanks

Windows XP Ruby 1.8.7 watir-webdriver (0.2.4) cucumber (0.10.3)

解决方案

Aslak:

Try this:

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 embedded image in the file that I emailed him, while I was still unable to do so in IE 8. I tried it out in Firefox 3.6 and the image appears as expected. The problem may have originally been with the embedding method itself (or rather, my use of it), but using Aslak's base64 solution it only fails to work in the Internet Explorer browser.

Aslak:

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

If being able to read cucumber html reports with screenshots in IE is really important to 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 the relative path you pass to embed is right (depending on where you write the html itself)

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

HTH, Aslak

这篇关于用于未链接到屏幕截图的屏幕截图的 Cucumber 嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆