fmondaini fmondaini - 10 months ago 55
Ruby Question

How to implement an AfterStep getting the Tag and passing the scenario as an argument?

I'm searching a way to implement an AfterStep(@tag) passing the scenario as an argument. Unfortunately, this isn't working and I couldn't find a way to do it.

I also looked into the Cucumber Hooks documentation, but that didn't help as well.

The way I'm trying to implement:

AfterStep('@screenshot') do |scenario|
# Add screenshot to baseline folder.
@helper =
@helper.take_screenshot(, 'screenshots/baseline')

When I run the tests, I get this error:

undefined method `name' for #<Cucumber::Core::Test::Result::Passed:0x007f2b818e6d50> (NoMethodError)

The objective here is to take a screenshot from the scenarios with the @screenshot tag.

Answer Source

As @Sam pointed out, using After('@screenshot') do |scenario| did the trick for me.