Skip to main content


Parallel execution of tests using Selenium-Grid and TestNG

Selenium-Grid allows you to run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.

When to use

  1. To reduce the time it takes for the test suite to complete a test pass.
  2. To run your tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems.

Selenium environment set up

  1. Download java and install
  2. Setting up the path for windows
  3. Download IE driver/Chrome driver
  4. Put IE driver/Chrome driver into system environment variables
  5. Download FF/Chrome/IE
  6. Download selenium-server-standalone-*.jar

Note: You need set up the environment for both hub and node.

How to start

Start hub:

java -jar selenium-server-standalone-2.45.0.jar -role hub

Start node:

java -jar selenium-server-standalone-2.45.0.jar -role node -port 5558 -hub

Here is the hub’s IP, we can use ipconfig command to get it. And 4444 is the default port (can be change by –port if you don’t want to use the default port). Obviously, you can start more than one node using the code above. One thing need to be careful is the port. When you start more than one node, you should using different port number to prevent the risk that port is already in used on your system.


When you got the information like “Registering the node to hub: xxxxxxxx”, that means node is ready to be used. You can use link http:// to get the node’s status.

Now selenium grid has been set up successfully, we can run a small case:


Using RemoteWebDriver() to connect the hub, and the connection information is After connected to hub, there will create a session on hub, meanwhile, hub will mapping the appropriate node depending on the request.

TestNG Configuration

parallel: set the default mechanism used to determine how to use parallel threads when running tests.

thread-count: set the default maximum number of threads to use for running tests in parallel


Here we set the parallel value as “tests” and thread-count as “2”. Then when we run scripts as testNG suite, it will use 2 parallel threads for tests. Also you can change parallel value to methods or classes. And the thread-count can be 3, 4, 5… It depends on how many parallel threads you want.

Best Practice

  1. Port: When you start more than one node in one machine, you should using different port number to prevent the risk that port is already in used on your system.
  2. Do not use “static” variable to initialize driver with parallel execution of scripts. When you define your field as static, then every thread has access to it and every thread can modify that memory space. Initialize driver with “static” works fine with non-parallel execution of scripts but not parallel execution.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us