开发者

selenium grid parallel execution

this is from selenium grid. How to write java/C# code to make parallel execution.

Is this enough?

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();

Because when I run http://localhost:4444/console there are 3 Available Remote Controls but 0 Active Remote Controls even if I run code from up.

Code from ant which I do not understand 100%. Why is there parameter

<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>


Why is there parameter

<arg value="-parallel"/>?

This is for testng. This would run all the methods/classes/tests in parallel rather than sequentially. You can see more about this property here. You have registered 3 RCs and ideally you should see all 3 being used for execution. You can check the grid console link to see the utilization - http://localhost:4444/console where localhost is the IP on which hub is running and port is the portnumber on which hub is listening to.

EDIT: Change your code to point to selenium hub port rather than RC port. By default Hub port will be 4444. Also make sure you have started the RC nodes with environment as *iehta.

`ISelenium selenium1 = new DefaultSelenium("localhost", 4444, "*iehta",` "http://localhost/");


What you are doing will work but will be slow and almost as bad as doing it in a truly serial way. This is because most of the calls in Selenium will block until completion. To really take advantage of the parallelisation offered by the Grid, you should multi-thread your code. Have one thread for each Selenium object.


You don't need to multi-thread your test code to run selenium instances in parallel (although you could if you really wanted to). A framework that handles thread forking can do it for you, such as TestNG, Maven Surefire, or Gradle. For example, my project proves this by demonstrating multiple instances running through grid on a single computer using Gradle to fork threads/instances: https://github.com/djangofan/selenium-gradle-example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜