maven - surefire-plugin 不尊重 threadCount 参数

标签 maven selenium selenium-webdriver junit maven-surefire-plugin

几天以来,我试图查看在并行运行 Selenium 测试的配置中我的错误在哪里。

我有一个带有 2 个节点的 Selenium Grid。
在我的 pom.xml 中,我设置了 Surefire 以 2 x 2 运行我的测试方法,然后是其他测试。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <executions>
                <execution>
                    <id>default-test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <parallel>methods</parallel>
                        <perCoreThreadCount>false</perCoreThreadCount>

                        <threadCount>2</threadCount>
                        <reuseForks>false</reuseForks>
                        <groups>
                            com.something.categories.Safe,
                            com.something.categories.Parallel
                        </groups>
                    </configuration>
                </execution>
                <execution>
                    <id>no-safe</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <excludedGroups>
                            com.something.categories.Safe,
                            com.something.Parallel
                        </excludedGroups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当我启动我的测试 mvn clean test -Dtest='TestAwesome' 包含在 TestAwesome 中的所有测试同时启动(我看到超过 2 个浏览器打开),因此不尊重我的 threadCount 值。

我错过了什么?

回答后版
这是我的部分 pom.xml 来解决我的问题
<profiles>
    <profile>
        <id>selenium-tests</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.18.1</version>
                    <configuration>
                        <parallel>all</parallel>
                        <threadCount>${threads}</threadCount>
                        <perCoreThreadCount>false</perCoreThreadCount>
                        <useUnlimitedThreads>true</useUnlimitedThreads>
                        <systemProperties>
                            <browser>${browser}</browser>
                            <screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
                            <gridURL>${seleniumGridURL}</gridURL>
                            <env>${env}</env>
                        </systemProperties>
                        <groups>${groups}</groups>
                        <excludedGroups>${excludedGroups}</excludedGroups>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

最佳答案

由于您使用的是足够现代的 surefire 版本,您可能想尝试将 threadCountMethods 参数而不是 threadCount 与 useUnlimitedThreads = true 结合使用,即使这看起来违反直觉。

surefire jUnit examples :

As of Surefire 2.7, no additional dependencies are needed to use the full set of options with parallel. As of Surefire 2.16, new thread-count attributes are introduced, namely threadCountSuites, threadCountClasses and threadCountMethods.



Fork options and parallel execution :

As an example with an unlimited number of threads, there is maximum of three concurrent threads to execute suites: parallel = all, useUnlimitedThreads = true, threadCountSuites = 3.

关于maven - surefire-plugin 不尊重 threadCount 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31478195/

相关文章:

java - 停止 IntelliJ 使用模块名称污染项目工具窗口?

python - PhantomJS 与 Selenium : Message: 'phantomjs' executable needs to be in PATH

python - 单击 Selenium 中某个类的第一个可见元素

Python:如何在 Selenium 中隐藏输出的 Chrome 消息?

java - 如何在 Eclipse 中配置 -D 参数

java - oss.sonatype.org 的 SBT 解析器无法正常工作

python - “phantomjs”可执行文件可能具有错误的权限

java - 如何从两个具有相同类名的独立 div 中获取文本?

java - org.testng.TestNGException : An error occurred while instantiating class

python - selenium.common.exceptions.WebDriverException : Message: Error loading page for the Firefox SSL