问题描述
几天以来,我试图查看我的配置中并行运行Selenium测试的错误之处.
Since several days, I tried to see where is my mistake in my configuration to run in parallel my Selenium tests.
我有一个带有2个节点的Selenium Grid.在我的pom.xml中,我将surefire设置为按2依次运行具有特定类别的测试方法和其他测试.
I have a Selenium Grid with 2 nodes.In my pom.xml, I have set surefire to run 2 by 2 the methods of my tests with a particular category then other tests.
<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中的所有测试是同时启动的(我看到打开了两个以上的浏览器),所以没有尊重我的threadCount值.
When I launch my test mvn clean test -Dtest='TestAwesome' all the tests contains in TestAwesome are launched in the same time (I see more than 2 browsers opended), and so does not respect my threadCount value.
我想念什么吗?
答案后的版本这是我的部分pom.xml,用于解决我的问题
Edition after answerHere my partial pom.xml to solve my issue
<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,即使看起来违反直觉.
Since you are using a modern-enough version of surefire, you might wanna try the threadCountMethods parameter instead of threadCount in combination with useUnlimitedThreads = true, even though it seems counter-intuitive.
这篇关于surefire-plugin不遵守threadCount参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!