如何跳过具有TestNG runner的唯一标记的特定场景

问题描述 投票:0回答:1

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

例如:功能文件具有@regression标记,我在所有运行者类中使用此标记来跨越各个国家/地区。由于某些国家/地区的数据问题,我想跳过一些国家的情况。(我正在使用TestNG runner)。我已经看到,在JUnit运行器中,您可以使用不跳过,但同样在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/下水道/maven-4.0.0.下水道"> 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>

enter image description here

cucumber cucumber-jvm
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.