Selenium webdriver 无法并行测试两个特征文件

Selenium webdriver 无法并行测试两个特征文件,selenium-webdriver,cucumber,selenium-grid,cucumber-jvm,parallel-testing,Selenium Webdriver,Cucumber,Selenium Grid,Cucumber Jvm,Parallel Testing,我是cucumber设计新手,我尝试并行测试两个特性文件(login.feature、registration.feature,两者都在src/test/java/features中),但无法并行运行这两个文件。有人能帮我吗 这是我的pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0&qu

我是cucumber设计新手,我尝试并行测试两个特性文件(login.feature、registration.feature,两者都在src/test/java/features中),但无法并行运行这两个文件。有人能帮我吗

这是我的pom.xml

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

这是我的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>
TestNG:

但是,如果您使用文本,不仅可以并行执行功能文件,还可以在功能文件中执行场景

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

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M1</version>
</plugin>

你看过这本指南了吗?cucumber jvm并行插件现在不推荐使用。Cucumber 4+具有本机支持并行运行。我还建议您参考@Marit建议的链接,或者您也可以试试这个``import io.cucumber.core.cli.main公共类MyRunner{public static void main(String[]args){main.run(新字符串[]{--threads)、“3”、“-t”、“@au和@nz”、“-g”、“com.your.glue”,“src/test/resources/features/”,},Thread.currentThread().getContextClassLoader();}}}``请接受答案,如果它有助于您解决问题。干杯:)谢谢您的回复。我已经更新了您提到的“maven surefire插件”,它的工作非常出色。谢谢。很高兴为您提供帮助。干杯:)
@RunWith(Cucumber.class)
@CucumberOptions(features = {"src/test/java/features/"},
    glue = {"stepDefinitions"},
    monochrome = true, tags = {"@RegressionTest"}
)
<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();
    }