如何跳过具有来自 TestNG 运行程序的唯一标记的特定场景

How to skip a specific scenario having unique tag from TestNG runner

我有很多场景的功能文件,运行 在多个国家/地区。为了 运行 在不同的国家,我创建了不同的 TestNG 运行ner classes。 我的问题是如何从特定的 运行ner 文件中跳过 运行 的场景。我正在 运行宁场景使用功能级别标签。

例如: 特征文件有 @regression 标签,我正在使用这个标签 所有 运行ner classes 到全国各地。由于一些数据问题 我想跳过某些国家/地区的某些情况。(我正在使用 TestNG 运行纳尔)。我已经看到在 JUnit 运行ner 中你可以使用 not to skip 但 同样在 TestNG 运行ner.

中不起作用

我在下面试过:

@CucumberOptions(
plugin = "com.cucumber.listener.ExtentCucumberFormatter:", 
monochrome = true, 
features = "src/features/Cart", 
tags = { "@regression and not @invalid"}

    @regression
    Feature: Validate login functionality for all countries

    @valid
      Scenario Outline: login with valid user access
        Given site launched
          And user enters "<username>"
          And user enters "<password>"
         When user clicks Sign In button
         Then display user home page

        Examples: 
          | username | password | 
          | xyz      | xyz123   | 
          | abc      | abc123   | 

      @invalid
      Scenario Outline: login with invalid user access
        Given site launched
          And user enters "<username>"
          And user enters "<password>"
         When user clicks Sign In button
         Then display user home page

        Examples: 
          | username | password | 
          | xyz      | xyz123   | 
          | abc      | abc123   | 

下面是我的 运行ner class 文件:

    package runner;
    import java.io.File;
    import java.util.HashMap;
    import java.util.Map;

    import org.junit.runner.RunWith;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;

    import com.cucumber.listener.Reporter;

    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    import cucumber.api.testng.AbstractTestNGCucumberTests;
    import utils.ConfigManagement;
    import utils.ExcelSheetManager;
    import utils.ExtentReportUtills;

    @CucumberOptions(plugin = "com.cucumber.listener.ExtentCucumberFormatter:",
    monochrome = true, features = "src/features/Cart", tags = { "@regression and not @invalid"},

            format = { "html:cucumber-html-reports1",
                    "json:cucumber-html-reports/cucumber.json" }, dryRun = false, glue = "steps")
    public class EU_IR_EN extends AbstractTestNGCucumberTests {

        public static Map<String, String> configDetails = new HashMap<>();

        @BeforeClass
        public static void setup() throws Exception {

            Map<String, String> SheetData = new HashMap<>();
            String key = "Cart";
            SheetData.put("SHEETNAME", key);
            configDetails = ConfigManagement.GetConfigDetailsForRCL(key);
            SheetData.putAll(configDetails);
            System.out.println("map at class level of runner1" + SheetData);
            ExcelSheetManager.setData(SheetData);
            System.out.println("first statement");
        }

        @AfterClass
        public static void prepareReport() throws Exception {
            ExtentReportUtills.UpdateExtentReport();
        }
    }

下面是我的POM.xml

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>cucumberTest</groupId>
<artifactId>FSCartUIAutomation</artifactId>
<version>1</version>
<packaging>jar</packaging>
<dependencies>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.0.6</version>
    </dependency>
    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>3.0.1</version>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>



    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.2.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>4.2.0</version>
    </dependency>

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>selenium-jupiter</artifactId>
        <version>2.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.14</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.14</version>
    </dependency>
    <!-- For excel file handling -->
    <dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
        <artifactId>jxl</artifactId>
        <version>2.6.12</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>

</dependencies>

<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>hindsighttesting.release</id>
        <name>Hindsight Software Release Repository</name>
        <url>http://repo.hindsightsoftware.com/public-maven</url>
    </pluginRepository>
</pluginRepositories>
<build>
    <plugins>


        <plugin>
            <groupId>com.hindsighttesting.behave</groupId>
            <artifactId>behave-maven-plugin</artifactId>
            <version>1.0.4</version>
            <executions>
                <execution>
                    <id>install6</id>
                    <phase>package</phase>
                    <goals>
                        <goal>features</goal>
                    </goals>

                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>GFSCart.xml</suiteXmlFile>
                </suiteXmlFiles>
                <printSummary>true</printSummary>
                <forkCount>4</forkCount>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>

                <!-- <source>${jdk.level}</source> <target>${jdk.level}</target> -->

            </configuration>
        </plugin>
    </plugins>
</build>

您可以使用标签 运行/跳过特定场景。

来自docs: 您可以告诉 Cucumber 忽略带有特定标签的场景:

使用 JUnit 运行ner class:

@CucumberOptions(tags = "not @smoke")
class RunCucumberTest {}