Executing tests Concurrently on different OS and Browsers with WebDriver using Java and TestNG Executing tests Concurrently on different OS and Browsers with WebDriver using Java and TestNG selenium selenium

Executing tests Concurrently on different OS and Browsers with WebDriver using Java and TestNG


Aditya,

Your code(testng.xml) for running parallel test on different-different or same system should be like below:

Testng.xml

 <!DOCTYPE suite SYSTEM "Http://testng.org/testng-1.0.dtd">    <suite name="My Sample Suite" verbose="3"  parallel="tests" thread-count="2">         <test name="Run on Firefox">        <parameter name="mybrowser"  value="firefox"/>        <parameter name="myip"  value="http://172.16.10.119:5566/wd/hub"/>        <classes>          <class name="testcases.Login"/>        </classes>     </test>      <test name="Run on Chrome">        <parameter name="mybrowser"  value="chrome"/>        <parameter name="myip"  value="http://172.16.10.106:5567/wd/hub"/>        <classes>          <class name="testcases.Login"/>        </classes>     </test>      </suite>here i am trying to acess one linux(ttp://172.16.10.119:5566) and one mac(http://172.16.10.106:5567) and sending its ip and browser as a parameter. To run it parallel i have mentioned in my <testsuite> tag as parallel="tests" thread-count="2"

I hope that you are pretty clear now.


Tester approach:

  • Make your test to be runnable as independent .jar file. Which means the test will not be actually a @Test but some method or piece of code inside main method
  • Pro tip: If you can, run the nodes against the same hub. This can be done if the computers are in same network and you can access these computers.
  • If this can be done, you will just run the .jar file twice, telling it where the huib is, and nodes will be assigned automatically
  • If this cannot be done, you will have to deploy these .jar files on each computer (node) and run them (requires two people in most cases)

Example:

My own computer has IP 10.131.7.11 inside local network. So I will run the hub and each node will just do this:

java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://10.131.7.11:4444/grid/register -port 7575 -browser browserName=firefox,version=18,platform=WINDOWS

Once the nodes are running, I will run the test twice. The hub will then automatically assign browsers to concrete node.

Developer approach:

  • you can use multithreading and run the test once, in two threads.

But since I am tester, I use the first approach :) And I did communicate with our developers who helped me to create multithreading test suite which is idiot proof (tested on myself :) )


Well, create another <test> tag and pass the other browser as the parameter for the second test. You might want to change parallel to tests or keep using classes. Also if you want to have different OSs then you need to have the Platform param too to be sent from the xml.