如何忽略黄瓜的特殊情况?

时间:2016-01-07 12:31:46

标签: java automation cucumber

  1. 我使用黄瓜来提供场景和java作为一种语言。
  2. 我需要在运行自动化测试时忽略特定场景。
  3. 我尝试使用@ignore语法,但它根本不起作用。
  4. 它没有跳过特定的场景,它继续执行我在功能文件中提供的所有测试场景。
  5. 功能文件

    @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
    

8 个答案:

答案 0 :(得分:19)

使用代码~@tag_name

排除具有特定标记的方案

cucumber --tags ~@tag_name

注意我使用了~符号。

  

这里需要注意的一点是,如果你的@ wip-tagged场景通过,Cucumber将退出状态为1(这提醒他们,自从他们通过后他们不再正在进行中)。

更新1

示例场景

@billing
Feature: Verify billing

  @important
  Scenario: Missing product description

  Scenario: Several products

运行标签

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

官方文件:https://github.com/cucumber/cucumber/wiki/Tags

答案 1 :(得分:12)

根据Cucumber.io 2种样式可以定义标记表达式。对于您的特定情况,要排除标有@ignore的步骤或功能,这两种样式将转换为:

  • 旧样式RewriteEngine On RewriteRule ^portal/?(.*)$ http://255.255.255.255/$1 [P]
  • 新款式cucumber --tags ~@ignore

令我惊讶的是,使用在Node.js v6.9.2上运行的相同的cucumber-js v1.3.1,我发现Windows版本只接受新样式,而Linux版本只接受旧样式。根据您的设置,您可能希望同时尝试两者,看看他们是否成功了。

答案 2 :(得分:10)

*。特征

@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);
    }
}

答案 3 :(得分:3)

@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

黄瓜选项

<\ n>在跑步者班级中,使用您不想要运行的如下所示的标签: tags = {&#34;〜@ avoid&#34;}

答案 4 :(得分:3)

我认为特殊标记@wip已经具有本机支持,并且可以在不添加任何其他代码的情况下使用。

它甚至有一个相关的命令行开关:

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

答案 5 :(得分:0)

使用JUnit runner class并参考https://cucumber.io/docs/cucumber/api/#ignoring-a-subset-of-scenarios

您可以创建自己的忽略标记

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(tags = "not @ignore")
public class RunCucumberTest {
}

然后只需标记这种情况:

  @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

答案 6 :(得分:0)

您可以在命令行中编写

  

mvn test -DCucumber.options =“-标记'@login而不是@grid'”

在外部加上双引号(“”),在内部加上单引号(')

答案 7 :(得分:0)

只需使用与CucumberOptions中定义的标签不同的标签即可。

假设在这里您使用“ @regression”运行测试:

@CucumberOptions(glue = { "stepDefinitions" }, tags = { "@regression" }, plugin = { "pretty", "io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm" }

在功能文件中,只需使用与“ @regression”不同的标签即可:

enter image description here