[英]Take a scenario failure screenshot
In my automated tests using Ruby / Capybara / Cucumber / Selenium, it is necessary that when some step of my test fails, the following steps will be performed:在我使用 Ruby / Capybara / Cucumber / Selenium 的自动化测试中,当我的测试的某些步骤失败时,有必要执行以下步骤:
Know how to help me with this question?知道如何帮助我解决这个问题吗?
Today the system takes a screenshot as evidence of the success of the scenario, but now I would like to take a failure screenshot without disturbing the execution of all my tests, following the execution of the next step or scenario.今天系统截屏作为场景成功的证据,但现在我想在不干扰我所有测试的执行的情况下截取失败的截图,跟随下一步或场景的执行。
Example code currently used as a hook for take screenshot:当前用作截屏钩子的示例代码:
After do | scenario |
screenshot = "log / screenshots / # {scenario.name} .png"
page.save_screenshot (screenshot)
embed (screenshot, 'image / png', 'Screen_Evidence')
end
This should create a screenshot at the point of failure for you.这应该为您在故障点创建一个屏幕截图。
config.after(:each) do |example|
if example.exception
screenshot = "log / screenshots / # {scenario.name} .png"
page.save_screenshot (screenshot) embed (screenshot, 'image / png', 'Screen_Evidence') end end page.save_screenshot(screenshot) embed(screenshot, 'image/png', 'Screen_Evidence') end end
You will probably want to limit this just to feature tests and optionally you could try refactoring your existing screenshot code into this same function.您可能希望将其限制为功能测试,并且您可以选择尝试将现有屏幕截图代码重构为相同的功能。
Try this way.试试这个方法。
After do |scenario|
if scenario.failed?
timestamp = "#{Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')}"
screenshot_name = "screenshot-#{scenario.name}-#{timestamp}.png"
screenshot_path = "#{Rails.root.join(provide path to save screenshots)}/#{screenshot_name}"
Capybara.page.save_screenshot(screenshot_path, full: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.