Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore particular scenario in cucumber?

  1. I am using cucumber to feed scenario and java as a language.
  2. I need to ignore particular scenario, while running an automation test.
  3. I have tried with below @ignore syntax, it doesn't work at all.
  4. It doesn't skip particular scenario, it keeps on executing all the test scenario, which I have feed in the feature file.

Feature File

@ActivateSegment Feature: Test for Activate segment    Scenario: Login     Given I navigate to M     And I enter user name      And I enter password      And I login to MM    Scenario: Open grid     Given I choose menu     And I choose Segments menu    Scenario: Open segment creation page     Given I click on New button     And I click on Segment button 
like image 727
selvi Avatar asked Jan 07 '16 12:01

selvi


People also ask

Can we skip step in Cucumber?

Thats what its supposed to do. Cucumber is not designed to allow you to skip steps and continue, because generally scenarios don't make sense when you skip steps.

How do you skip a particular scenario in Cucumber?

You can ignore or skip Cucumber Tests using tags. This works both for Scenario as well as Feature. You can skip a scenario, set of scenarios or all scenarios in a feature file. You can also use this with conjunction with AND or OR.

Why some steps are skipped in Cucumber?

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 I exclude tags in Cucumber?

OR logic is like this: tags = {"@Tag1, @Tag2"} //one of these Tags must be present or: tags = {"~@Tag1, ~@Tag2"} //one of these Tags must not be present, the Rest will be executed!


2 Answers

Use tag ~@tag_name

To exclude scenarios with a certain tag

cucumber --tags ~@tag_name 

Note I used ~ symbol.


One thing to note here is that Cucumber will exit with a status of 1 if your @wip-tagged scenarios pass (it’s a reminder that they’re not works in progress anymore since they pass).

UPDATE 1

Sample Scenario

@billing Feature: Verify billing    @important   Scenario: Missing product description    Scenario: Several products 

Running Tags

cucumber --tags @billing            # Runs both scenarios cucumber --tags @important          # Runs the first scenario cucumber --tags ~@important         # Runs the second scenario (Scenarios without @important) 

Offical document: https://github.com/cucumber/cucumber/wiki/Tags

like image 59
Aravin Avatar answered Sep 25 '22 13:09

Aravin


According to Cucumber.io there are 2 styles in which a tag expression can be defined. For your specific case, to exclude steps or features marked with @ignore, these 2 styles translate into:

  • old style : cucumber --tags ~@ignore
  • new style : cucumber --tags "not @ignore".

To my surprise, using the same cucumber-js v1.3.1 running on Node.js v6.9.2, I found that the Windows version accepted only the new style, while the Linux one accepted only the old style. Depending on your setup, you may want to try both and see if you succeed with any of them.

like image 29
M. F. Avatar answered Sep 21 '22 13:09

M. F.