How to skip the steps of a cucumber?

I have a script like:

  • Given that I go to this page
  • When I print a cucumber
  • And I click
  • Then I should see the text
  • And I should not see the line

If I run this script, it will follow all 5 steps. But I want to skip the 4th step (then I should see the text) and complete the 5th step.

Please give me your suggestions. Thank you in advance.:)

+6
source share
2 answers

TL DR - do not do this - you are (probably) wrong. And you cannot (easily) do this. As Aslak (one of the main creators of the cucumber) wrote:

A step may have the following results:

  • undefined (no corresponding stepdef)
  • pending (corresponding to a stepdef that raises a PendingException)
  • passed (corresponding stepdef that throws nothing)
  • failed (corresponding stepdef that throws an exception that is not a PendingException)
  • skipped (step following the step that caused some kind of exception (undefined, pending or failed))

What you are asking for is a new kind of result - ignored. Perhaps implemented by throwing an IgnoredException. This would mean that the skip should be changed to: (the step following the step that threw any exception (undefined, pending, or failed) - unless the exception was ignored by the Exception)

I'm not sure I like it. It sounds more complicated than it should be. You already have the necessary information, something is not working - your step will be either unsuccessful or pending. I do not see to continue the following steps. You still have to complete the error / pending step.

As long as you are reminded that β€œwork is needed here” do not think that it almost complicates Cucumber in order to tell you what kind of work needs to be done ...

Aslak

The whole discussion is here: http://comments.gmane.org/gmane.comp.programming.tools.cucumber/10146

+13
source

I had to skip steps conditionally based on environments. I used next to skip steps. Here is an example of how to do what you wanted.

 Then /^I should see the text/$ do next if @environment == 'no text' ... <The actual step definition> ... end 
+5
source

All Articles