1

I’m writing the error/failures of my steps to a file with this function:

def addToErrorFile(errorName)
    open('error.txt', 'a') { |f| f.puts"#{errorName}"}
end

This function is located in a lot of places in my test flow.

To make it easier to read it in the end, I would like to add the step name (Then /I go to…) and also the scenario (Scenario: login to..).

Is there a way to copy those into the function?

Nir Ortal
  • 77
  • 12
  • This might help - http://stackoverflow.com/questions/31864767/accessing-the-scenario-title-and-example-in-a-cucumber-after-hook – slindsey3000 Sep 23 '15 at 17:49

2 Answers2

1

You could put some code in your before and after scenario hooks that writes to the error log. That should break it up a bit and make it easier to read. Something like this.

Before do |scenario|
  your_logging_method(scenario.name)
end

After do |scenario|
    your_logging_method(scenario.name)
end

And there is an AfterStep hook too, though I haven't used it.

AfterStep do |step|
  another_logging_method(step)
end

You may have to call some methods on the step variable to get it in a useful format.

Here's a link to the cucumber hooks documentatioon - https://github.com/cucumber/cucumber/wiki/Hooks

alannichols
  • 1,496
  • 1
  • 10
  • 20
0

it wouldn't be better to use ruby (begin rescue ensure ) and put the code in there. You save your test session and you can progress your test to next steps, where you can put line of code to save name of next step to file

Hikaryu
  • 317
  • 5
  • 17