并行执行没有发生在Cucumber JVM 4.0.0和Junit测试运行器上

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了并行执行没有发生在Cucumber JVM 4.0.0和Junit测试运行器上相关的知识,希望对你有一定的参考价值。

我无法使用黄瓜JVM 4.0.0和Junit testrunner并行运行功能。我只有一个浏览器实例打开,一旦执行完成,浏览器关闭并再次打开以执行下一个功能。根据我在Maven surefire中的3个线程数,我希望同时打开3个浏览器实例以运行3个功能。我遵循了以下link,但仍然没有成功。功能一个接一个地运行。我使用Pico容器进行DI.I跟着这个link更新不同版本的Surefire插件但仍然没有运气。我为IO.cucumber Jars尝试了4.0.0和4.2.0。我已经尝试过从2.19到2.22的不同版本的surefire但仍然没有运气。我有3个功能文件,每个都有一个标记为“@Parallel”的场景大纲。我不知道哪里出错。我试过并行surefire插件中的“both”和“methods”。我的Junit版本是4.12。

我的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>

我的测试员如下。

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{
}    
答案

这可能是无关紧要的。

我试图用Junit实现Cucumber,因为它在功能级别上是并行的限制,我转移到了Cucumber-TestNG。

TestNG它自己支持Junit。因此,只有当前设计需要改变跑步者类别

请看一下https://github.com/bhargavQA/selenium-java-cucumber-framewrok.git

这是使用Cucumber TestNG完成的,并支持场景级别的并行执行。

另一答案

我怀疑你可能打算在配置中使用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>
另一答案

你应该使用maven-failsafe-plugin,而不是万无一失。我将failafe与com.github.temyers -cucumber-jvm-parallel-plugin结合使用

另一答案

我有同样的问题(尝试在pom中启用并行,但功能似乎按顺序运行)。

在搜索时我发现这个bug https://github.com/cbeust/testng/issues/987声称在使用testng的maven中忽略了parallel和threadcount配置。然后我意识到我依赖于testng而我根本没有使用它(除了一些断言,我转而使用junit)。

我可以在你的pom中看到对testng的依赖。您可以尝试删除依赖项或确保使用一个修复了testng问题的版本,然后重试。

以上是关于并行执行没有发生在Cucumber JVM 4.0.0和Junit测试运行器上的主要内容,如果未能解决你的问题,请参考以下文章

使用与黄瓜集成的柑橘框架的并行集成测试执行

无法使用 testng.xml 执行 Cucumber 功能文件

JVM垃圾回收

JVM垃圾回收

Cucumber-jvm共享驱动程序示例

在java中将Cucumber-jvm步骤作为String