Home Guide Selenium remotewebdriver : Difference between webdriver and remotewebdriver

Selenium remotewebdriver : Difference between webdriver and remotewebdriver

By Neha Vaidya, Community Contributor -

Selenium WebDriver is a tool used to execute automated test cases on various browsers. The object of the webdriver is a browser. Selenium remotewebdriver implements the webdriver interface to execute test cases.

This article discusses what a remotewebdriver is and how it differs from a webdriver.

What is a Selenium remotewebdriver?

The RemoteWebDriver class implements the WebDriver interface to execute test scripts through the RemoteWebDriver server on a remote machine. This class is implemented under the package below:

java.lang.Object
org.openqa.selenium.remote.RemoteWebDriver

Remotewebdriver Architecture:

  • RemoteWebDriver consists of a server and a client.
  • The server is a component that listens on a port for various requests from a RemoteWebDriver client. Once the request is received, it forwards the request to the browser driver: FirefoxDriver, IEDriver, or ChromeDriver.
  • The client libraries serve as a RemoteWebDriver client. The client translates test script requests to JSON payload and sends it across to the RemoteWebDriver server using the JSON wire protocol. The diagram below depicts the remote webdriver architecture.Selenium RemoteDriver Architecture
  • When test cases are executed, the WebDriver client libraries link with the browser drivers directly. On the other hand, if one tries to execute tests remotely, the WebDriver client libraries communicate with the RemoteWebDriver server. Then, the server links to either of the browser drivers the WebDriver client requests for.

Selenium remotewebdriver Installation

The setup process here is simple. But, it requires the user to be aware of the Selenium Grid and its installation. To understand the setup process in detail, refer to our Selenium Grid Tutorial.

Once the Selenium grid is installed, follow the steps below to configure the Selenium remotewebdriver.

  • Start the server on the command prompt using the command:
    java -jar selenium-server-standalone-3.3.1.jar -role hub

    The hub should now be running on localhost port 4444

  • Open another command prompt to add a node to the hub:
    java -jar selenium-server-standalone-3.3.1.jar -role node -hub http://localhost:4444/grid/register
  • Open a web browser and navigate to: http://localhost:4444/grid/console. The grid console page will be visible. Connect to Selenium Hub to execute test cases.

To know the various modifiers of Remote Webdriver class, refer to this document.

Selenium remotewebdriver execution with example

When the Selenium server and hub are connected and running, one can write a test case using remotewebdriver.

  • To run a remote WebDriver client, first, connect to RemoteWebDriver. Point the URL to the address of the server running the tests. Also, set up the desired capabilities to customize the client. The example below instantiates a remote WebDriver object pointing to the remote web server, www.myexamplebrowserstack.com.
FirefoxOptions firefoxOptions = new FirefoxOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://www.myexamplebrowserstack.com"), firefoxOptions);
driver.get("http://www.google.com");
driver.quit();
  • Next, add the desired capabilities to customize the configuration. The remoteweddriver runs on JSON wireless protocol. Hence it becomes necessary to add desired capabilities and execute the test on Chrome browser and windows platform.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("browserVersion", "74");
chromeOptions.setCapability("platformName", "Windows 10");
WebDriver driver = new RemoteWebDriver(new URL("http://www.myexamplebrowserstack.com"), chromeOptions);
driver.get("http://www.google.com");
driver.quit();

  • The next step is to transfer the files from the client machine to the remote server. This can be achieved using the Local file detector. The remotewebdriver transfers the files from the client to the remote server. The command below helps to set the file detector.
driver.setFileDetector(new LocalFileDetector());
  • Finally, the file can be uploaded to execute the test cases
driver.get("Path of the file");
WebElement uploadfile = driver.findElement(By.id("myfile"));
uploadfile.sendKeys("File_path_value");

Selenium Remote Webdriver vs Selenium Webdriver

Selenium Remote WebdriverSelenium Webdriver
It implements a Webdriver interfaceWebdriver object is a browser
Controls the desired browser in the node PC over GridWebdriver object controls the web browser
RemoteWebDriver object instantiation controls any browser in the node PC which is on Windows, Mac, Linux etc. platforms.On instantiating the driver object, class implementations will be launched
Contains additional methods for class implementationComprises of fewer methods for implementing interfaces

Advantages of Selenium Remote Webdriver

  • It allows for execution of Automation test suites or batches on multiple machines at the same time
  • It enables test case execution with browsers that are not available on the current OS. In simple terms, it is OS independent.
  • It returns an exception with an accompanying screenshot so testers know what issue has occurred.

BrowserStack Logo Run Selenium Tests on 2000+ Browsers & Devices Get Started Free