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

sel*_*lvi 21 java automation cucumber

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

特征文件

@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
Run Code Online (Sandbox Code Playgroud)

Ara*_*vin 22

使用标签 ~@tag_name

排除具有特定标记的方案

cucumber --tags ~@tag_name
Run Code Online (Sandbox Code Playgroud)

注意我使用了~符号.


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

更新1

示例场景

@billing
Feature: Verify billing

  @important
  Scenario: Missing product description

  Scenario: Several products
Run Code Online (Sandbox Code Playgroud)

运行标签

cucumber --tags @billing            # Runs both scenarios
cucumber --tags @important          # Runs the first scenario
cucumber --tags ~@important         # Runs the second scenario (Scenarios without @important)
Run Code Online (Sandbox Code Playgroud)

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

  • 看起来 `~@skip` 语法不再有效并且不再记录。“not @skip”是新的出路。https://cucumber.io/docs/cucumber/api/#ignoring-a-subset-of-scenarios (2认同)
  • 正如其他答案中提到的,“~”字符是旧式的,对于当前版本的 cucumber-js 在 Windows 中不起作用。使用--tags“不是@tag_to_exclude” (2认同)

M. *_* F. 14

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

  • 旧款式:cucumber --tags ~@ignore
  • 新风格:cucumber --tags "not @ignore".

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


Ran*_*ili 13

*.特征

@skip_scenario
Scenario: Hey i am a scenario
  Given blah blah
  And blah blah blah
Run Code Online (Sandbox Code Playgroud)

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);
    }
}
Run Code Online (Sandbox Code Playgroud)


Cod*_*ker 13

使用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 {
}
Run Code Online (Sandbox Code Playgroud)

然后像这样标记场景:

  @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

Run Code Online (Sandbox Code Playgroud)