Dalan Miller
Dalan Miller

Reputation: 3

Capturing an exit code for passing or failing Cucumber scenarios

I am writing Gherkin scenarios, I have an After hook I am currently working on. I want to be able to increment two variables (passing, failing) depending on the status of a scenario after it has been ran.

Does Cucumber return an exit code, and if it does, how do you capture it in code?

My tests are being written in RubyMine, and I am testing a web-application using Watir-Webdriver (just in case you need to know).

Upvotes: 0

Views: 1529

Answers (1)

hidro
hidro

Reputation: 12541

You can use scenario.failed? or scenario.passed? in your After hook to check for scenario status:

After do |scenario|
  # Do something after each scenario.
  # The +scenario+ argument is optional, but
  # if you use it, you can inspect status with
  # the #failed?, #passed? and #exception methods.

  if scenario.failed?
    subject = "[Project X] #{scenario.exception.message}"
    send_failure_email(subject)
  end
end

Reference: https://github.com/cucumber/cucumber/wiki/Hooks

Upvotes: 2

Related Questions