Selenium Grid and TestNG

How to run parallel test scripts using Selenium Grid and TestNG

Pushkar Deshpande
Automation Testing

--

How to run parallel test execution

  • Setting up Selenium Grid Server
  • Adding node to hub
  • Creating and executing Selenium script in parallel with TestNG

Setting up selenium Server:

1. Download Selenium server (.jar) from : Selenium Grid

2. Place the .jar file in the hard disk location

3. Open command prompt and go to the location where .jar file is placed

4. Run following command :

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

5. Verify whether hub is running using followin URL :

http://localhost:4444/grid/console

Adding node to hub

1. Open command prompt (new instance as hub is already running on 1 instance) and go to the location where .jar is placed

2. Run following command :

java -jar selenium-server-standalone-2.52.0.jar -role webdriver -hub http://172.16.15.140:4444/grid/register -port 5568

(Note that the IP address provided should be of the client machine. If you are running scripts on same machine then use same IP address of the server machine.)

Above command will add a single node to the hub. To add multiple nodes open and run same command in new command prompt. Make sure that the port will be different for each node.

eg.

3. Above node will work successfully for Firefox

4. If you are trying to add a node to hub for internet explorer (IE) use following command :

java -jar selenium-server-standalone-2.52.0.jar -role webdriver -hub http://172.16.15.140:4444/grid/register -port 5555 -Dwebdriver.ie.driver=”C:/Selenium/Grid/Resource/IEDriverServer.exe”

5. Verify whether hub and nodes are running using followin URL :

http://localhost:4444/grid/console

Creating and executing Selenium script in parallel with TestNG

Java Code and XML Code

Java Code
XML File

Run the code using configuration

--

--