Web automation testing using Selenium RemoteWebDriver

Selenium is a tool that helps us to test the UI of web applications on a variety of browsers (Chrome, Firefox, …) completely automatically. It uses the WebDriver concept such as ChromeDriver, FirefoxDriver, RemoteWebDriver … to realize its ideas. Each browser, each different environment will have their own WebDriver. In this tutorial, I will introduce you to Selenium RemoteWebDriver!

Selenium  RemoteWebDriver is a WebDriver that helps us to run the test remotely. This means, you can run the test code on your machine, but the code execution will happen on another machine.

To do that, first you have to run Selenium Standalone Server on the machine where you want to execute the test code and this Selenium Standalone Server must be configured to support the browser you want to run the test.

For example, if I want to test the website https://huongdanjava.com/ on Chrome browser using Selenium RemoteWebDriver, my steps will be as follows:

– I will download Selenium Standalone Server from https://docs.seleniumhq.org/download/. Selenium Standalone Server is an executable .jar file.

– Next, I will download ChromeDriver from https://sites.google.com/a/chromium.org/chromedriver/downloads. For this step, you have to check the Chrome version you are using to download ChromeDriver properly for that version.

I am using Chrome version 72.0.3626.109 (Official Build) (64-bit) on macOS so I will download ChromeDriver 72.0.3626.69 for macOS at https://chromedriver.storage.googleapis.com/index.html?path=72.0.3626.69/. The downloaded file will be a .zip file so you need to unzip this file!

– Now I will start Selenium Standalone Server with ChromeDriver with the following command:

with -Dwebdriver.chrome.driver is the parameter I use to declare the environment variable pointing to ChromeDriver. For different browsers, the environment variable name needs to be different, for example, for Firefox, the environment variable name might be -Dwebdriver.firefox.driver, as long as the value needed to point to FirefoxDriver! If you need Selenium Standalone Server to support multiple browsers, you can declare additional environment variables to WebDriver of those browsers.

selenium-server-standalone-3.141.59.jar is the file name of Selenium Standalone Server, the file name may be different for you.

My results when running the above command:

Web automation testing using Selenium RemoteWebDriver

OK, now you was able to run a Selenium Standalone Server! Next, I will create a new Maven project to see how RemoteWebDriver works!
My project is as follows:

Web automation testing using Selenium RemoteWebDriver

With Selenium Remote Driver dependency as follows:

In case if you want to use multiple WebDriver, you can declare using Selenium Java dependency as follows:

For simplicity, I just created a class with main() method to run the example!

OK, now let’s try using Selenium Remote Web Driver to open the https://huongdanjava.com/ website with Chrome browser!

First, you need to initialize RemoteWebDriver object with capabilities for Chrome browser as follows:

In which “http://localhost:4444/wd/hub/” is the Web Driver Hub address that we started with Selenium Standalone Server. Here, because I run Selenium Standalone Server on my machine, the value of the host is localhost, if you run it on another machine, you need to change this value!

To open the website https://huongdanjava.com/, you need to call the get() method with a value of https://huongdanjava.com/.

OK, let’s try running this example!

You will see a new Chrome window open and accessible to https://huongdanjava.com/ website as follows:

Web automation testing using Selenium RemoteWebDriver

Now you can continue writing the UI test code.

Add Comment