gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:31:18 25 4
gpt4 key购买 nike

我无法使用 Cucumber JVM 4.0.0 和 Junit testrunner 并行运行功能。我只有一个浏览器实例打开,一旦执行完成,浏览器关闭并再次打开以执行下一个功能。根据我在 Maven surefire 中的线程数 3,我希望同时打开 3 个浏览器实例以运行 3 个功能。我已经关注了以下 link ,但仍然没有成功。这些功能一个接一个地运行。我已经将 Pico 容器用于 DI。我遵循了这个 link用于更新不同版本的 Surefire 插件,但仍然没有运气。我已经为 IO.cucumber Jars 尝试了 4.0.0 和 4.2.0。我尝试了从 2.19 到 2.22 的不同版本的 surefire,但仍然没有运气。我有 3 个功能文件,每个文件都有一个标记为“@Parallel”的场景大纲。我不确定哪里出了问题。我尝试了并行作为surefire 插件中的“两者”和“方法”。我的 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。所以在当前的设计中只需要更改 runner 类

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

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

关于java - Cucumber JVM 4.0.0 和 Junit 测试运行程序不会发生并行执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53711882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com