几天以来,我试图查看在并行运行Selenium测试时配置中的错误所在。
我有一个带有2个节点的Selenium Grid。在我的pom.xml中,我将surefire设置为以特定类别而不是其他测试的方式逐个运行测试方法。
<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值。
我想念什么吗?
答案后的版本这里是我的部分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的足够现代的版本,因此您可能想要结合使用useUnlimitedThreads = true尝试使用threadCountMethods参数而不是threadCount ,即使它看起来是违反直觉的。
从Surefire 2.7开始,无需使用任何其他依赖项即可使用整套并行选项。从Surefire 2.16开始,引入了新的线程计数属性,即threadCountSuites,threadCountClasses和threadCountMethods。
例如,线程数量不受限制,最多有三个并发线程来执行套件:parallel = all,useUnlimitedThreads = true,threadCountSuites = 3。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句