Ruby code to retrieve scenario outline and example name in step definition

76 views
Skip to first unread message

Abhinav Tiwari

unread,
Apr 11, 2016, 2:38:18 PM4/11/16
to Cukes
Hi,
I am using:
Ruby + Watir + eCuke + Rubymine : For Test Automation

I am trying to create a new customized HTML report of test script run with Scenario Details and Screenshots. 

I am able to capture screenshots and embed that in the html report. But I am not able to retrieve Scenario Outline name and Examples name in my ruby code at step definition.
Please note that I do not want to retrieve this information from hooks file.

Can anyone suggest how I can I retrieve this information during runtime?
Thanks in advance.

Chuck van der Linden

unread,
Apr 12, 2016, 5:58:38 PM4/12/16
to Cukes
You can try this (found on SO).

      scenario_title = scenario.respond_to?(:scenario_outline) ? scenario.scenario_outline.title : ''
      scenario_title_example = scenario.respond_to?(:name) ? scenario.name : ''
      scenario_full_title = scenario_title + scenario_title_example

If that does not work I can dig out some code I have from a prior project where I saved screenshots and other files on failing scenario's/examples using the scenario (outline) name + example and see if that is a better solution

Abhinav Tiwari

unread,
Apr 19, 2016, 11:25:55 AM4/19/16
to Cukes
@Chuck van der Linden - Thank you, but this doesn't work from the step definition ruby code.

If you can post some code from your prior project, I can try hitting that too. Thanks in advance!
Reply all
Reply to author
Forward
0 new messages