当前位置: 首页 > 知识库问答 >
问题:

不能并行测试两个cucumber特征文件

叶鸿煊
2023-03-14
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven 
     4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>NorthernMachine_Automation</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber.version>4.2.0</cucumber.version>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.github.temyers</groupId>
                <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                <version>2.1.0</version>
                <executions>
                    <execution>
                        <id>generateRunners</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>generateRunners</goal>
                        </goals>
                        <configuration>
                            <!-- Mandatory -->
                            <!-- comma separated list of package names to scan for glue code -->
                            <glue>foo, bar</glue>
                            <outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
                            <!-- The directory, which must be in the root of the runtime classpath, containing your feature files.  -->
                            <featuresDirectory>src/test/resources/features/</featuresDirectory>
                            <!-- Directory where the cucumber report files shall be written  -->
                            <cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
                            <!-- comma separated list of output formats json,html,rerun.txt -->
                            <format>json</format>
                            <!-- CucumberOptions.strict property -->
                            <strict>true</strict>
                            <!-- CucumberOptions.monochrome property -->
                            <monochrome>true</monochrome>
                            <!-- The tags to run, maps to CucumberOptions.tags property you can pass ANDed tags like "@tag1","@tag2" and ORed tags like "@tag1,@tag2,@tag3" -->
                            <tags></tags>
                            <!-- If set to true, only feature files containing the required tags shall be generated. -->
                            <filterFeaturesByTags>false</filterFeaturesByTags>
                            <!-- Generate TestNG runners instead of default JUnit ones. -->
                            <useTestNG>false</useTestNG>
                            <!-- The naming scheme to use for the generated test classes.  One of 'simple' or 'feature-title' -->
                            <namingScheme>simple</namingScheme>
                            <!-- The class naming pattern to use.  Only required/used if naming scheme is 'pattern'.-->
                            <namingPattern>Parallel{c}IT</namingPattern>
                            <!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per scenario.  FEATURE generates a runner per feature. -->
                            <parallelScheme>SCENARIO</parallelScheme>
                            <!-- This is optional, required only if you want to specify a custom template for the generated sources (this is a relative path) -->
                            <customVmTemplate>src/test/resources/cucumber-custom-runner.vm</customVmTemplate>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <fork>true</fork>
                    <!--<executable>C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe</executable> -->
                    <!--    <executable>${env.JAVA_HOME}\bin\javac.exe</executable>-->
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <mainClass>BuyAGiftFramework.utilities.SendEmailFile</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <forkCount>5</forkCount>
                    <reuseForks>true</reuseForks>
                    <includes>
                        <include>**/*IT.class</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.4</version>
                <configuration>
                    <goalPrefix>cucumber-jvm-parallel</goalPrefix>
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>
                <executions>
                    <execution>
                        <id>mojo-descriptor</id>
                        <goals>
                            <goal>descriptor</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>help-goal</id>
                        <goals>
                            <goal>helpmojo</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-html</artifactId>
        <version>0.2.3</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>
    <!-- Extent Reports -->
    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.1.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.26-incubating</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>3.6.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/log4j/log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>


    <dependency>
        <groupId>com.github.javafaker</groupId>
        <artifactId>javafaker</artifactId>
        <version>0.15</version>
    </dependency>

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.temyers</groupId>
        <artifactId>cucumber-jvm-parallel-plugin</artifactId>
        <version>4.2.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>4.2.6</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.1.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>6.2.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>6.4.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>
package runners;

import cucumber.api.CucumberOptions;
import io.cucumber.junit.Cucumber;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.junit.runner.RunWith;
import org.testng.annotations.DataProvider;

@RunWith(Cucumber.class)
@CucumberOptions(features = {"src/test/java/features/"},
    glue = {"stepDefinitions"},
    monochrome = true, tags = {"@RegressionTest"}
)


public class MainRunnerTest extends AbstractTestNGCucumberTests {

MainRunnerTest mainRunnerTest;

@DataProvider(parallel = true)
public Object[][] features() {
    return mainRunnerTest.features();
}
}

这是我的

共有1个答案

朱海超
2023-03-14

JUnit:

是的,您可以在Cucumber中并行执行特性文件。使用JUnit和Maven测试执行插件。实际上,使用JUnit,只有功能文件可以并行执行,而不是在同一个文件中执行场景。Maven Surefire可以用来执行运行程序。

将Surefire插件配置添加到POM的构建部分。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M1</version>
    <configuration>
        <parallel>methods</parallel>
        <useUnlimitedThreads>true</useUnlimitedThreads>
    </configuration>
</plugin>

按以下方式更新runner类:

@RunWith(Cucumber.class)
@CucumberOptions(features = {"src/test/java/features/"},
    glue = {"stepDefinitions"},
    monochrome = true, tags = {"@RegressionTest"}
)

测试:

但是,如果使用TextNG,不仅可以并行执行特性文件,还可以在特性文件中执行场景。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M1</version>
</plugin>
@Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }
 类似资料:
  • 问题内容: 我在src / test / resources / feature /中有以下功能文件(单独的功能文件),我想并行运行它们。就像:一个功能文件必须在chrome中执行,而另一个功能文件必须在firefox中执行,如@Tags名称所述。 有人可以帮助我实现这一点吗?我使用的是cumul-java 1.2.2版本,并且使用AbstractTestNGCucumberTests作为运行程序

  • 使用Cucumber,我们创建了由不同场景组成的不同功能文件。我们记住的一件事是,每个场景都独立于所有其他场景。 问:我们可以对所有的特征文件或场景进行并行执行吗?

  • 我对cucumber测试框架不熟悉。我的目标是使用Junit和Maven并行运行场景文件。我遵循了以下步骤:https://cucumber.io/docs/guides/parallel-execution/ 我有两个功能文件 特点1: 特点2: 我还有一个runner文件,如下所示: 我的POM如下: 当我用mvn清洁安装运行cucumber测试时,两个场景都使用不同的线程运行。但我运行使用运

  • 我已经写了我的firsy cucumber特征文件。当我将功能文件作为Cucumber功能运行时,会出现以下错误 “警告:cucumber-jvm的--format选项不推荐使用。请改用--plugin。”-我在我的@CucumberOptions of runner类中使用了“plugin”,但仍然得到相同的错误 场景:验证登录页面#c:/selenium/regressiontest/modu

  • 我有一些cucumber特性,可以通过IDE运行find功能,但现在我需要通过命令行使用“mvn test”命令来执行它们。 CMD输出如下:

  • Cucumber测试没有并行运行(Cucumber jvm并行插件)? 如果我使用runner类执行测试,一次将执行一个功能文件,但是当将以下插件添加到POM文件时,似乎没有功能文件执行? 即使我指向了正确的功能文件文件夹? 我的POM文件: