How to ignore a specific scenario in cucumbers?

  • I am using a cucumber script to serve and java as a language.
  • I need to ignore a specific scenario when running an automation test.
  • I tried with @ignore syntax below, it doesn't work at all.
  • It does not skip a specific script, it continues to execute the entire test script that I have in the function file.

Function 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 
+17
source share
7 answers

Use the tag ~@tag _name

To exclude scripts with a specific tag

 cucumber --tags ~@tag _name 

Note I used the ~ character.


It should be noted that Cucumber will exit with status 1 if your @ -type-tagged scripts pass (this is a reminder that theyre not working in the process since they pass).

UPDATE 1

Scenario example

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

Tag launch

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

White Paper: https://github.com/cucumber/cucumber/wiki/Tags

+19
source

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

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

To my surprise, using the same cucumber-js v1.3.1 that runs on Node.js v6.9.2, I found that the Windows version only supports the new style, and the Linux version only the old one. Depending on your settings, you can try both options and see if you succeed with any of them.

+12
source

*. Function

 @skip_scenario Scenario: Hey i am a scenario Given blah blah And blah blah blah 

Cucumberhooks.java

 package CucumberHooks; import cucumber.api.Scenario; import cucumber.api.java.Before; public class CucumberHooks { @Before("@skip_scenario") public void skip_scenario(Scenario scenario){ System.out.println("SKIP SCENARIO: " + scenario.getName()); Assume.assumeTrue(false); } } 
+10
source
 @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 @avoid Scenario: Open segment creation page Given I click on New button And I click on Segment button 

in cucumbers

in the runner class, use tags as shown below that you do not want to run: tags = {"~ @ avoid"}

+3
source

I believe that the special @wip tag already has built-in support and can be used without any other code additions.

It even has an associated command line switch:

-w, --wip Fail if there are any passing scenarios.

+3
source

Using the JUnit runner class and with reference to https://cucumber.io/docs/cucumber/api/#ignoring-a-subset-of-scenarios

You can create your own ignore tag.

 import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions(tags = "not @ignore") public class RunCucumberTest { } 

Then just mark the script like this:

  @ignore Scenario: Check if all the 3 categories of cats are displayed Given I open the Cats App When I view the home screen Then I should see all three cats categories displayed 
0
source

From the command line you can write

mvn test -DCucumber.options = "--tags '@login, not @grid'"

put double quotes ("") on the outside and single quotes (') on the inside

0
source

All Articles