简体   繁体   English

使用Ruby自动将场景名称添加到Selenium中的屏幕快照文件名

[英]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.

相关问题 如何使用Ruby在Selenium Webdriver中使用屏幕快照名称中包含日期和时间的屏幕快照? - How to take screenshot in selenium webdriver with ruby with date and time included in screenshot name? 使用ruby更改方案失败时ios模拟器中calabash拍摄的屏幕截图的路径 - change path of screenshot taken by calabash in ios simulator on scenario failure using ruby Ruby Selenium屏幕快照到特定的文件位置 - Ruby Selenium Screenshot to specific File location Ruby + Selenium-执行每个步骤后截屏 - Ruby + Selenium - Take a screenshot with each step executed 谁能建议如何使用 ruby​​ selenium 截取整个网页的屏幕截图? - Can anyone suggest how to take screenshot of full webpage using ruby selenium? 如何在 Ruby 中使用 selenium-webdriver/capybara 截取完整浏览器页面及其元素的屏幕截图? - How to take a screenshot of a full browser page and its elements using selenium-webdriver/capybara in Ruby? 黄瓜红宝石救援例外情况名称 - cucumber ruby rescue exception Scenario name 拍摄场景失败截图 - Take a scenario failure screenshot 在ruby中使用拉力赛REST自动添加任务以进行拉力赛 - add task automatically to rally using rally REST in ruby 使用ruby的特定dom元素的屏幕截图 - screenshot of specific dom element using ruby
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM