我正在使用 maven surefire 插件运行 selenium webDriver 并使用 testNG,并且能够并行化我的测试并重用一个 JVM 实例。出于某种原因,我不确定如何运行超过 5 个。我尝试设置
<threadCountMethods> 10</threadCountMethods>
希望它一次运行 10 个线程,而不是我认为可能是默认值的 5 个。
我正在对方法进行并行化,如下所示:
` org.apache.maven.插件 maven-surefire-插件 2.17
<configuration>
<useUnlimitedThreads>true</useUnlimitedThreads>
<threadCountMethods>10</threadCountMethods>
<parallel>methods</parallel>
<forkCount>0</forkCount>
<reuseForks>true</reuseForks>
<suiteXmlFiles>
<suiteXmlFile>kingHenry.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>`
并且套件文件配置如下:
<suite name="Suite" parallel="methods" >
<parameter name="seleniumHost" value="192.168.1.74" />
<parameter name="seleniumPort" value="4444" />
<parameter name="logHost" value="localhost" />
<parameter name="logPort" value="5000" />
<parameter name="networklogging" value="false" />
<test name="Showdme">
<parameter name="browser" value="phantomjs" />
<classes>
<class name="com.something.suites.kingHenry" />
<methods>
<include name="testScenario1" />
<include name="testScenario2" />
<include name="testScenario3" />
<include name="testScenario4" />
<include name="testScenario5" />
<include name="testScenario6" />
</methods>
</classes>
</test>
</suite>
我在这里展示了列出的 6 种并行化方法,但在附加的图像中,一次仅运行 5 个浏览器实例。我想知道我是否需要在我的 pom.xml 文件中编辑或添加配置属性,或者是否存在用于限制 chromedriver 的 5 个实例的正在使用的 selenium 网格的设置。任何帮助将不胜感激......关于 surefire 插件的线程/ fork 的一些文档有点令人困惑。
最佳答案
如果您使用的是 Selenium 网格,那么将您的测试一次限制为 5 个是有道理的。工厂 Selenium 网格属性允许网格运行:
网络驱动程序: - 5 谷歌浏览器 - 5 火狐 - 1 个浏览器
旧版(RC): - 5 谷歌浏览器 - 5 火狐 - 1 个浏览器
您可以使用节点配置 json 文件更改这些值。
nodeConfig.json
{
"capabilities":
[
{
"browserName": "*chrome",
"maxInstances": 2,
"seleniumProtocol": "Selenium"
}
... (any other browser capabilities here)
],
"configuration":
{
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 10,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hubPort": 4444
}
}
然后在运行节点时:
java -jar selenium-server-standalone.jar -role node -nodeConfig nodeConfig.json ...
关于java - testNG/selenium webdriver 限制为 5 个并行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24680384/