Site icon TestingDocs.com

RemoteWebDriver Tutorial

Introduction

In this post, we will discuss RemoteWebDriver. First of all, Remote WebDriver is an implementation class of the WebDriver interface that can use to execute test code on a remote machine via the RemoteWebDriver server.

There are two parts to RemoteWebDriver

Servlet is a Java class that runs in a Web container. Class diagram of RemoteWebDriver

 

RemoteWebDriver Server

To Run the server

There are two ways to use the server: command line or configured in code. To start the RemoteWebDriver server execute the following command on the remote machine.

For example:
/>   java -jar selenium-server-standalone<<Version>>.jar

The server has 2 different timeouts, which can be set as follows:

java -jar selenium-server-standalone-<<VERSION>>.jar -timeout=30 -browserTimeout=90

 

 

 

 

browserTimeout :Controls how long in seconds the browser is allowed to hang.
timeout : Controls how long in seconds the client is allowed to be gone before the session is reclaimed.

Note that : If the Webdriver tests forget to terminate the remote sessions, then the server might leak memory. If you keep long-running sessions, then probably we need to stop/quit the server every now and then or increase memory with -Xmx JVM option. This is the case with limited hardware resources.

Docker Containers

We can fix these issues by running scalable and distributed grid on Docker containers.

https://www.testingdocs.com/scalable-selenium-grid-with-docker-compose/

Server as Servlet

The process is as simple as mapping the DriverServlet to a URL. Also, it is possible to host the web page in a lightweight container, such as Jetty or dedicated App server container like Tomcat or JBoss, if you run the servers for other purpose.

Remote WebDriver client

When you execute your tests locally, the WebDriver client libraries talk to FireFoxDriver /ChromeDriver/EdgeDriver etc.

When we try to execute the tests remotely, the WebDriver client libraries talk to the RemoteWebDriver server and the server talks to either the FireFoxDriver, ChromeDriver, Edge Driver etc on the Node machines/containers.

Code Snippet

  public class SampleCodeExample {
      public static void main(String[] args){
         DesiredCapabilities capabilities =new DesiredCapabilities();
         capabilities.setBrowserName("Firefox");
         RemoteWebDriver remotedriver =null;
        try{
              remotedriver = new RemoteWebDriver (new URL("http://
127.0.0.1:444/we/hub"),capabilities);
         }  catch (MalformedURLException mfe){
                mfe.printStackTrace();
           }
    }
}

 

To customize the browsers and their capabilities consider using FirefoxOptions, ChromeOptions, etc. to run remote Web driver tests.

You can view all of the sessions that are established with the RemoteWebDriver server by navigating to the default URL :  http://127.0.0.1:4444/we/hub. ( However, we can configure this too according to our own needs ).

Note that this is old and classic standalone mode. The architecture has significantly changed with Selenium 4 with new Distributed mode that we can leverage some of the limitations and disadvantages.

https://www.testingdocs.com/selenium-grid-distributed-mode/

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Exit mobile version