![](/img/trans.png)
[英]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.