[英]Automatically add Scenario name to filename of screenshot in Selenium using Ruby
I'm using Selenium, writing in Ruby. 我正在使用Selenium,用Ruby编写。 I've configured my env.rb file to save a screenshot of any failed tests that I run. 我已将env.rb文件配置为保存我运行的任何失败测试的屏幕截图。 The problem is it's hard to determine the scenario/step that failed as the filename is generic. 问题是由于文件名是通用的,因此很难确定失败的方案/步骤。 I've managed to time stamp the filename using this: 我设法使用以下方式为文件名加上时间戳:
After do |scenario|
if scenario.failed?
screenshot_file = "screenshot - #{Time.now.strftime('%Y-%m-%d %H-%M-%S')}.png"
page.save_screenshot(screenshot_file)
end
end
Is there a way in which I can get this filename to also pull the name of the scenario that failed so that it could be "scenario# date time.png"? 有没有一种方法可以获取此文件名,同时提取失败的方案的名称,使其可以是“ scenario#date time.png”? I've seen a few examples online, none of which work. 我在网上看到了一些示例,但都没有用。
Thank you 谢谢
...
screenshot_file = "screenshot-#{scenario.name}-#{Time.now.strftime('%Y-%m-%d %H-%M-%S')}.png"
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.