Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure cucumber stops execution when a step fails?

Cucumber keeps executing even after a step definition has failed, and it outputs not only the failing steps, but also the passing ones. What option do I need to use in order to ensure that Cucumber stop executing as soon as it has encountered a failing step?

This is my cucumber.yml file

<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
autotest: <%= std_opts %> features --color
like image 545
picardo Avatar asked Jul 18 '11 23:07

picardo


People also ask

How do you continue execution in cucumber if one steps fails?

Cucumber skips all steps after a failed step by design. Once a step has failed, the test has failed and there should be no reason to perform the next steps. If you have a need to run the additional steps, likely your scenario is testing too many different things at once.

How do you stop the cucumber test?

Pressing Ctrl + C and Ctrl + C twice. It should stop immediately.

How do you fail a step in cucumber scenario?

To fail a scenario you just need an assertion to fail, no need to set the status of the scenario. Cucumber will take care of that if an assertion fails. For testng you can use the SoftAssert class - http://testng.org/javadocs/org/testng/asserts/SoftAssert.html You will get plenty tutorials for this.

How do you mark a fail in cucumber?

If you use the conditional statement like "If", then you have a control to tell cucumber not to stop. and you can dictate whether a particular condition is a pass or a failure.. Now cucumber might have some library functions that can you help you with this situation.


2 Answers

Use a cucumber hook:

After do |s| 
  # Tell Cucumber to quit after this scenario is done - if it failed.
  Cucumber.wants_to_quit = true if s.failed?
end

Or, raise an exception.

The recommended way is using a cucumber hook, though.

like image 120
Kenny Meyer Avatar answered Oct 11 '22 06:10

Kenny Meyer


This lets fail fast be invoked from the command line:

# `FAST=1 cucumber` to stop on first failure
After do |scenario|
  Cucumber.wants_to_quit = ENV['FAST'] && scenario.failed?
end
like image 22
Dan Kohn Avatar answered Oct 11 '22 06:10

Dan Kohn