Run Test in Selenium Grid

In this Tutorial, You will see, How can you Run Test in Selenium Grid. We will use the Selenium Grid with TestNG. To run the TestCases with Selenium Grid on the remote machine. You need to use RemoteWebDriver .


What is RemoteWebDriver?

RemoteWebDriver is an implementation class of the WebDriver interface that a test script developer can use to execute their test scripts via the  RemoteWebDriver server on a remote machine.

There are two parts to RemoteWebDriver; a server and a client.


The RemoteWebDriver server is a component that listens on a port for various requests from a RemoteWebDriver client. Once it receives the requests, it forwards them to any of the following: Firefox Driver, IE Driver, or Chrome Driver, whichever is asked.


Create Object of RemoteWebDriver?

To create the Object of RemoteWebDriver or invoke the RemoteWebDriver. We need to follow the below-mentioned steps.


  1. First, you need to create the object of DesiredCapabilities and assign the Browser to it. The browser could be firefox, chrome, and IE. We are using firefox in our example.
  2. In the Second step, you need to declare the BrowserName for DesiredCapabilities. The name could be firefox, chrome, and iexplore.
  3. In the third step, you need to declare the Platform for DesiredCapabilities. It could be android, Linux, iOS, and Windows. Because we can run our tests on the server as well so we will choose ANY in the option.
    All code will look like this –
    DesiredCapabilities cap = DesiredCapabilities.firefox();
  4. In Last, we need to create the Object of Remote webdriver and pass the URL of selenium Hub and DesiredCapabilities object to it as the parameter. It will look like-



Execute Test cases using Selenium Grid

Now we will see, How can we execute the Test Cases using TestNG and Selenium Grid.


TestCase – Open the and verify the Page Title.

We will create the Test Script for above Test Case and execute it using, Selenium Grid.

You know, To run Tests using Selenium Grid, We need RemoteWebDriver and you have seen how can we invoke the RemoteWebDriver in Selenium.


Now let’s see the Test Script code for the above Test Case.


In the above code, first, we are invoking the RemoteWebDriver and later on, we are using simple selenium code.

Now let’s see how can we execute this-

  1. To execute the Test using Selenium Grid, First invoke the Selenium Grid Hub.
  2. After invoking the Hub, Invoke the Selenium Grid Node.
  3. Now modify the testng.xml file, according to your test case and package. For example, we are using below mentioned xml in testng.xml file.

    <!DOCTYPE suite SYSTEM “” >

    <suite name=”Grid Test” >
    <test name=”Verify Yahoo Title”>

    <class name=”com.SeleniumBix.SampleTests.YahooTitle” />


  4. Now run your Test Case using testng.xml .


You will see, No browser will open and close but your test has been executed. So that you will not be able to see the execution of Test case but you can see the Test Result on eclipse console and in the TestNG test report.

0 Comment

Leave a Reply