如何在cucumber中忽略特定场景? 我使用cucumber为场景提供素材,并将java作为一种语言 我需要在运行自动化测试时忽略特定场景 我试过下面的@ignore语法,它根本不起作用 它不会跳过特定的场景,它会继续执行所有的测试场景,我在特性文件中提供了这些场景

如何在cucumber中忽略特定场景? 我使用cucumber为场景提供素材,并将java作为一种语言 我需要在运行自动化测试时忽略特定场景 我试过下面的@ignore语法,它根本不起作用 它不会跳过特定的场景,它会继续执行所有的测试场景,我在特性文件中提供了这些场景,java,automation,cucumber,Java,Automation,Cucumber,功能文件 @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

功能文件

@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

使用tag
~@tag\u name

排除带有特定标记的场景

cucumber --tags ~@tag_name
注意我使用了
~
符号


这里需要注意的一点是,如果@wip标记的场景通过,Cucumber将以1的状态退出(这是一个提醒,它们在通过后不再进行工作)

更新1 示例场景 运行标签 官方文档:

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

  • 旧式
    黄瓜——标记~@ignore
  • 新样式
    cumber——标记“not@ignore”
令我惊讶的是,使用Node.js v6.9.2上运行的cucumber js v1.3.1,我发现Windows版本只接受新样式,而Linux版本只接受旧样式。根据您的设置,您可能希望同时尝试这两种方法,并查看是否成功使用其中任何一种方法

@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
黄瓜的选择

在runner类中,使用如下所示的您不想运行的标记: 标签={“~@avoid”}

*。功能

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

我相信这个特殊的标签
@wip
已经有了本机支持,并且可以在不添加任何其他代码的情况下使用

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


-w,--wip失败,如果存在任何传递场景。

使用
JUnit runner类并参考

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

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


从命令行,您可以编写

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


将双引号(“”)置于外部,将单引号(')置于内部

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

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

@CucumberOptions(glue={“stepDefinitions”},tags={“@regression”},plugin={“pretty”,
“io.qameta.allure.cucumber4jvm.allu4JVM”}

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


您在@Options注释中使用了哪些标记?我提到的注释,@ignore是用来忽略场景的注释。import org.junit.runner.RunWith;import cucumber.api.junit.cumber;@RunWith(cumber.class)@cumber.Options(features={“classpath:my_feature.feature”},tags={~@ignore})您好,我是新来的。您能详细说明一下,我需要在哪个文件中添加上述注释,无论是在.feature文件还是在.java文件中。我需要忽略上面的场景,例如Open Segment。在参考了一些网站后,我真的很困惑。在哪个文件中,我需要添加junit注释以跳过某个场景。您的java测试文件如下所示上面有它。你可能应该把它添加到问题中…我尝试过你的解决方案。它一点都没有跳过。你能用示例详细说明一下,如何在我的功能文件中使用上面的ta g。嗨,Selvi,很抱歉延迟了回复。请找到更新的答案。我尝试过忽略语法。它根本不起作用。代码:功能:作为图书所有者列出拥有的图书我想列出我的图书,以便我可以查找我拥有的图书@ignore Scenario:列出现有图书,因为我已经添加了“示例规范”当我查看图书列表时,我的图书列表包含“Specification by Example”Runner:Cumber{tags=[“~@ignore”]}@selvi,这是Cucumber的基本功能,它肯定会起作用。请分享您的功能文件和运行命令。看起来
~@skip
语法不再起作用,也不再有文档记录。
而不是@skip
是一种新方法。我发现了一个问题,显然,如果我跳过这样的测试,Cucumber将以代码1退出,wh即使跳过了测试,我的管道也失败了。这对我有效,其他人没有,我正在使用Intellij。我必须在“运行配置”程序参数中添加--tags选项:比如--plugin org.jetbrains.plugins.cucumber.java.run.cumberjvmsmformatter--单色--tags“~@avoid”我不确定信念是否是最好的信息来源;-)我只使用
@wip
标记进行了测试,但它不起作用(cucumber-java8 4.2.0)。显示标记的正确用法。
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