[英]How to take screenshot in selenium webdriver with ruby with date and time included in screenshot name?
[英]Automatically add Scenario name to filename of screenshot in Selenium using Ruby
我正在使用Selenium,用Ruby编写。 我已将env.rb文件配置为保存我运行的任何失败测试的屏幕截图。 问题是由于文件名是通用的,因此很难确定失败的方案/步骤。 我设法使用以下方式为文件名加上时间戳:
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
有没有一种方法可以获取此文件名,同时提取失败的方案的名称,使其可以是“ scenario#date time.png”? 我在网上看到了一些示例,但都没有用。
谢谢
...
screenshot_file = "screenshot-#{scenario.name}-#{Time.now.strftime('%Y-%m-%d %H-%M-%S')}.png"
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.