How to ignore particular scenario in cucumber?

2020-02-23 06:38发布

  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

7条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-23 06:40
@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 cucumber options

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

查看更多
走好不送
3楼-- · 2020-02-23 06:51

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

查看更多
祖国的老花朵
4楼-- · 2020-02-23 06:52

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 tag the scenario like so:

  @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

查看更多
唯我独甜
5楼-- · 2020-02-23 06:54

*.feature

@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);
    }
}
查看更多
Summer. ? 凉城
6楼-- · 2020-02-23 06:56

From the command line, you can write

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

put double quote ("") outside and single quote(') inside

查看更多
Viruses.
7楼-- · 2020-02-23 06:58

I believe the special tag @wip already has native support, and can be used without any other code additions.

It even has a related command line switch:

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

查看更多
登录 后发表回答