这是来自selenium grid的。如何编写java/C#代码进行并行执行。
这足够了吗?
ISelenium selenium1 = new DefaultSelenium("localhost", 5555, "*iehta", "http://localhost/");
ISelenium selenium2 = new DefaultSelenium("localhost", 5556, "*iehta", "http://localhost/");
ISelenium selenium4 = new DefaultSelenium("localhost", 5557, "*iehta", "http://localhost/");
selenium1.Start();
selenium2.Start();
selenium3.Start();因为当我运行http://localhost:4444/console时,有3个可用的遥控器,但没有活动的遥控器,即使我从上往上运行代码。
来自蚂蚁的代码,我不是100%理解。为什么会有参数
<arg value="-parallel"/>
<target name="run-demo-in-parallel" description="Run Selenium tests in parallel">
<java classpathref="demo.classpath"
classname="org.testng.TestNG"
failonerror="true"
>
<sysproperty key="java.security.policy" file="${basedir}/lib/testng.policy"/>
<sysproperty key="webSite" value="${webSite}" />
<sysproperty key="seleniumHost" value="${seleniumHost}" />
<sysproperty key="seleniumPort" value="${seleniumPort}" />
<sysproperty key="browser" value="${browser}" />
<arg value="-d" />
<arg value="${basedir}/target/reports" />
<arg value="-suitename" />
<arg value="Selenium Grid Demo In Parallel" />
<arg value="-parallel"/>
<arg value="methods"/>
<arg value="-threadcount"/>
<arg value="10"/>
<arg value="-testclass"/>
<arg value="com.thoughtworks.selenium.grid.demo.WebTestForASingleBrowser"/>
</java>
</target>发布于 2011-08-02 21:29:01
为什么会有参数
<arg value="-parallel"/>?这是给testng的。这将并行运行所有方法/类/测试,而不是顺序运行。您可以查看有关此属性here的更多信息。您已经注册了3个RCs,理想情况下,您应该看到所有3个RCs都用于执行。您可以检查网格控制台链接以查看利用率- http://localhost:4444/console,其中localhost是运行集线器的IP,port是监听集线器的端口号。
编辑:将您的代码更改为指向selenium集线器端口,而不是RC端口。默认情况下,集线器端口为4444。还要确保您已启动RC节点,并将环境设置为*iehta。
`ISelenium selenium1 = new DefaultSelenium("localhost", 4444, "*iehta",` "http://localhost/");发布于 2011-08-02 05:54:50
你正在做的事情将会奏效,但会很慢,而且几乎和以真正的串行方式做同样糟糕。这是因为Selenium中的大多数调用都会阻塞,直到完成。要真正利用网格提供的并行化,您应该将代码多线程。为每个Selenium对象分配一个线程。
发布于 2013-12-27 06:56:08
您不需要将测试代码多线程来并行运行selenium实例(尽管如果您真的想要的话,也可以这样做)。处理线程派生的框架可以为您完成这项工作,例如TestNG、Maven Surefire或Gradle。例如,我的项目通过演示在一台计算机上通过网格运行的多个实例来证明这一点,使用Gradle来派生线程/实例:https://github.com/djangofan/selenium-gradle-example
https://stackoverflow.com/questions/6904065
复制相似问题