简体   繁体   English

Cucumber JVM 4.0.0和Junit测试运行程序不会发生并行执行

[英]Parallel Execution not happening with Cucumber JVM 4.0.0 and Junit test runner

I am unable to run features in parallel using cucumber JVM 4.0.0 and Junit testrunner. 我无法使用Cucumber JVM 4.0.0和Junit testrunner并行运行功能。 I just have one browser instance opening and once the execution is completed, browser closes and opens again for next feature execution.As per my thread count of 3 in Maven surefire, i expect 3 browser instances to be opened concurrently for running 3 features. 我只打开了一个浏览器实例,执行完成后,浏览器关闭并再次打开以执行下一个功能。根据我在Maven surefire中的3个线程数,我希望同时打开3个浏览器实例以运行3个功能。 I have followed the following link , but still not successful. 我已遵循以下链接 ,但仍未成功。 The Features run one after another. 这些功能一个接一个地运行。 I have used Pico container for DI.I followed this link for updating different version of Surefire plugin but still no luck. 我使用了Pico容器进行DI。我按照此链接更新了不同版本的Surefire插件,但仍然没有运气。 i have tried 4.0.0 as well as 4.2.0 for IO.cucumber Jars. 我已经尝试了4.0.0以及IO.cucumber Jars的4.2.0。 I have tried different versions of surefire from 2.19 to 2.22 but still no luck.I have 3 features files and each of them have one scenario outline tagged as "@Parallel".I am not sure where am going wrong.I have tried parallel as "both" and "methods" in surefire plugin. 我尝试了从2.19到2.22的不同版本的surefire,但是仍然没有运气。我有3个功能文件,每个文件都有一个场景大纲标记为“ @Parallel”。我不确定哪里出了问题。 surefire插件中的“两个”和“方法”。 My Junit version is 4.12. 我的Junit版本是4.12。

My pom is as below. 我的pom如下。

 <?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>testcase</groupId>
    <artifactId>xyzproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>xyzproject</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cocumber.version>4.0.0</cocumber.version>
        <picocontainer.version>4.0.0</picocontainer.version>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>http://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>repo.bodar.com</id>
            <url>http://repo.bodar.com</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-java</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-picocontainer</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-junit</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-jvm</artifactId>
            <version>4.0.0</version>
        </dependency>


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

        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>or.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11-beta3</version>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-spis</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.8.0</version>
        </dependency>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.7.1</version>
        </dependency>


        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cocumber-reporting</artifactId>
            <version>3.10.0</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>


        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-core</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>4.1.2</version>
        </dependency>

        <!--REPORTING -->

        <dependency>
            <groupId>com.googlecode.totallylazy</groupId>
            <artifactId>totallylazy</artifactId>
            <version>1.20</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>1.20</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.totallylazy</groupId>
            <artifactId>totallylazy</artifactId>
            <version>1.20</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.13.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>6.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compailer-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <fork>true</fork>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.20</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadcount>3</threadcount>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cocumber-reporting</artifactId>
                <version>0.0.7</version>

                <dependencies>
                    <dependency>
                        <groupId>com.googlecode.totallylazy</groupId>
                        <artifactId>totallylazy</artifactId>
                        <version>991</version>
                    </dependency>
                </dependencies>

                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>

                        <configuration>
                            <projectname>cucumber-jvm-example</projectname>
                            <outputDirectory>${project.build.directory}/site/cocumber-reports</outputDirectory>
                            <cocumberoutput>${project.build.directory}/cocumber.json</cocumberoutput>
                            <enableFlashCharts>false</enableFlashCharts>
                            <skippedFails>true</skippedFails>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

My testrunner is as below. 我的测试运行器如下。

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"html:target/cucumber-html-report",
"json:target/cucumber.json","pretty:target/cucumber-pretty.txt",
"usage:target/cucumber-usage.json, "junit:target/cucumber-results.xml"},
features={"src/test/resources/featuresfiles"},strict=false,dryRun=false,
glue={"Stepdef_new.stepdefinitions"},
tags={"@Parallel"}
}

Public class TestRunner{
}    

This could be irrelevant . 这可能无关紧要。

I tried to implement to Cucumber with Junit and because of it's limitation of being parallel on feature level and I moved to Cucumber-TestNG. 我尝试使用Junit来实现Cucumber,并且由于它在功能级别上是并行的 ,所以我选择了Cucumber-TestNG。

TestNG it self supports Junit. 它自己支持TestNG的TestNG。 So only runner class need to changed in current design 因此,在当前设计中仅需要更改跑步者级别

Please have a look this once https://github.com/bhargavQA/selenium-java-cucumber-framewrok.git 请一次看一下https://github.com/bhargavQA/selenium-java-cucumber-framewrok.git

This is being done with Cucumber TestNG and supports parallel execution at scenario level. 这是通过Cucumber TestNG完成的,并支持方案级别的并行执行。

I suspect you may have meant to use maven-surefire-plugin instead of maven-surefire-report-plugin in your configuration. 我怀疑您可能打算在配置中使用maven-surefire-plugin而不是maven-surefire-report-plugin

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <parallel>methods</parallel>
                <threadcount>3</threadcount>
            </configuration>
        </plugin>

You should be using maven-failsafe-plugin, not surefire. 您应该使用的是maven-failsafe-plugin,而不是surefire。 I used failsafe in combination with com.github.temyers -cucumber-jvm-parallel-plugin 我将故障保护与com.github.temyers -cucumber-jvm-parallel-plugin结合使用

I had the same issue (trying enabling parallel in pom but features seem to run in sequence). 我遇到了同样的问题(尝试在pom中启用并行,但是功能似乎按顺序运行)。

While searching I found this bug https://github.com/cbeust/testng/issues/987 claiming that the parallel and threadcount configuration is ignored in maven with testng. 在搜索时,我发现了这个错误https://github.com/cbeust/testng/issues/987,声称在使用testng的maven中忽略了并行和线程计数配置。 I then realized that I had a dependency to testng while I was not using it at all (apart from some assertions that I switched to use junit). 然后,我意识到我完全不使用testng时有一个依赖关系(除了一些断言是我改用junit)。

I can see in your pom a dependency to testng. 我可以在您的pom中看到对testng的依赖。 You could try remove the dependency or ensure you use one version having the testng issue fixed and try again. 您可以尝试删除依赖项,或确保使用一个已解决testng问题的版本,然后重试。

You can try to remove the testng dependency or to explicitly say to use the surefire-junit like 您可以尝试删除testng依赖项,或明确表示要使用surefire-junit

<plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${surefire.version}</version>

                        <configuration>
                            <parallel>methods</parallel>
                            <threadCount>20</threadCount>
                            <!-- <useUnlimitedThreads>true</useUnlimitedThreads> -->
                            <includes>
                                <include>**/JUnitRunner.java</include>
                            </includes>
                        </configuration>


                        <dependencies>
                            <!-- https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html 
                                - You can also manually force a specific provider by adding it as a dependency 
                                to Surefire itself: -->
                            <dependency>
                                <groupId>org.apache.maven.surefire</groupId>
                                <artifactId>surefire-junit47</artifactId>
                                <version>${surefire.version}</version>
                            </dependency>
                        </dependencies>

                    </plugin>
                </plugins>

Try this: https://github.com/rhapsodyman/cucumber4-parallel 试试这个: https : //github.com/rhapsodyman/cucumber4-parallel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM