首页 > 解决方案 > 如何跳过具有来自 TestNG 运行器的唯一标签的特定场景

问题描述

我有很多场景的功能文件,这些场景在多个国家/地区运行。为了在不同的国家/地区运行,我创建了不同的 TestNG 运行器类。在这里,我的问题是如何跳过从特定运行程序文件运行的方案。我正在使用功能级别标签运行场景。

例如:功能文件有@regression标签,我在所有跑步者类中使用这个标签到整个国家。由于某些国家/地区的数据问题,我想跳过某些国家/地区的某些情况。(我正在使用 TestNG runner)。我已经看到在 JUnit 跑步者中你可以使用 not to skip 但在 TestNG 跑步者中同样不起作用。

我在下面试过:

@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   | 

下面是我的跑步者类文件:

    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>

在此处输入图像描述

标签: cucumbercucumber-jvm

解决方案


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

文档中:您可以告诉 Cucumber 忽略带有特定标签的场景:

使用 JUnit 运行器类:

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

推荐阅读