Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between RemoteWebDriver and WebDriver?

I actually couldn't find a good explanation of whats the difference between RemoteWebDriver and a WebDriver in Selenium.

Here's a code where eclipse told me to cast WebDriver to RemoteWebDriver.

(!((RemoteWebDriver) driver).getSessionId().toString().contains("null"))

So why shouldn't I just use RemoteWebDriver instead of WebDriver?

like image 353
jackra1n Avatar asked Aug 16 '19 17:08

jackra1n


People also ask

What is RemoteWebDriver in Selenium WebDriver and use of it?

Selenium RemoteWebDriver is used to execute the browser automation suite on a remote machine. In other words, RemoteWebDriver is a class that implements the WebDriver interface on the remote server. The browser driver classes like FirefoxDriver, ChromeDriver, InternetExplorerDriver, etc.

What is the difference between WebDriver and WebElement?

Anything that is present on the web page is a WebElement such as text box, button, etc. WebElement represents an HTML element. Selenium WebDriver encapsulates a simple form element as an object of the WebElement. It basically represents a DOM element and all the HTML documents are made up by these HTML elements.

Is Selenium and WebDriver the same?

Selenium IDE is for less-technical testers to create a visual, grid-like example of what they want to test. WebDriver should be used for more complex tests that need to loop, perform setup or interact with external systems.

Can't we use RemoteWebDriver new ChromeDriver ()?

The reason you do not often see a new ChromeDriver being assigned to a RemoteWebDriver variable is because from the perspective of a test, there is no functional difference between a WebDriver object and a RemoteWebDriver object. The level of abstraction provided by RemoteWebDriver is simply not very useful.


1 Answers

RemoteWebDriver is a concrete class that implements interface WebDriver.

RemoteWebDriver class contains additional methods that are not declared by interface WebDriver. The method 'getSessionId()' is one of them.

Hence, your object needed to be explicitly downcasted to use getSessionId method since WebDriver itself does not have knowledge of any method or variable which is purely defined by RemoteWebDriver.

Coming to the question - "why shouldn't I just use RemoteWebDriver instead of WebDriver?"

Yes you may use RemoteWebDriver instead of WebDriver, however it makes the code non-compliant with the design principle - 'Code to the interface'

Your code will work fine though without any issues.

However, it will not have flexibility to use other driver implementations that may come in future (though very unlikely) which implements WebDriver but does not extend RemoteWebdriver. In such case, a variable of type RemoteWebDriver cannot be assigned to an object of the class is which WebDriver's implementation but not extending RemoteWebDriver

like image 163
Sachin Ramdhan Boob Avatar answered Oct 04 '22 19:10

Sachin Ramdhan Boob