1

I'm using Selenium, writing in Ruby. I've configured my env.rb file to save a screenshot of any failed tests that I run. 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"? I've seen a few examples online, none of which work.

Thank you

2
  • have you tried scenario.name Commented Sep 4, 2014 at 8:53
  • I did, but i wasn't sure where to put that. Would it be #{scenario.name}#{time etc}? Commented Sep 4, 2014 at 9:29

1 Answer 1

1
...
screenshot_file = "screenshot-#{scenario.name}-#{Time.now.strftime('%Y-%m-%d %H-%M-%S')}.png"
...
Sign up to request clarification or add additional context in comments.

3 Comments

I tried that, the screenshot fails to save. I'm wondering whether it's how i've named my scenario... "Scenario: US1244-1.1 Confirm that the View all fleet records form contais a section to allow user to Filter results by Registration number and Vehicle make" Maybe it doesn't like that
it could be the file length issue. Use a short scenario name and check if it works.
That was exactly it. Your help is much appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.