黄瓜嵌入的屏幕截图不链接到屏幕截图

发布于 2024-11-12 04:51:20 字数 692 浏览 3 评论 0原文

从 Cukes Google Group 交叉发布:

我尝试了多种保存屏幕截图的方法, 但最终选择了 watir-webdriver 中内置的方法。不 无论我使用哪种方法,我都无法成功嵌入 Cucumber HTML 报告中此图像的链接。

在 c:\ruby\cucumber\project_name\features\support\hooks.rb 中,我使用:

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

带有文本“Screenshot”的链接已添加到报告中,但 URL 是 项目目录路径 ("c:\ruby\cucumber\project_name") 而是 而不是直接链接到文件 ("c:\ruby\cucumber\project_name\screenshot.png")。我尝试了多种不同的图像格式 和使用 Dir.pwd 的直接路径每次都有相同的结果。

我缺少什么?

感谢

Windows XP 红宝石 1.8.7 watir-webdriver (0.2.4) 黄瓜 (0.10.3)

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:\ruby\cucumber\project_name\features\support\hooks.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:\ruby\cucumber\project_name") rather
than a direct link to the file ("c:\ruby\cucumber\project_name\screenshot.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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-11-19 04:51:20

阿斯拉克:

试试这个:

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 能够看​​到嵌入的
我通过电子邮件发送给他的文件中的图像,
虽然我仍然无法做到这一点
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)

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

 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')

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

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

HTH,阿斯拉克

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文