WebDriver vs ChromeDriver

In Selenium 2 - Java, what's the difference between

ChromeDriver driver = new ChromeDriver();

and

WebDriver driver = new ChromeDriver();

? I saw how both of them were used in various lessons, examples, etc., and I'm not sure about the difference between using ChromeDriver and WebDriver objects.

+9
source share
4 answers

Satish's answer is correct, but in more unprofessional conditions, ChromeDriver is specifically and only the driver for Chrome. WebDriver is a more general driver that can be used for different browsers ... IE, Chrome, FF, etc.

If you only care about Chrome, you can create a driver using

 ChromeDriver driver = new ChromeDriver(); 

If you want to create a function that returns a driver for the specified browser, you can do something like below.

 public static WebDriver startDriver(Browsers browserType) { switch (browserType) { case FIREFOX: ... return new FirefoxDriver(); case CHROME: ... return new ChromeDriver(); case IE32: ... return new InternetExplorerDriver(); case IE64: ... return new InternetExplorerDriver(); default: throw new InvalidParameterException("Unknown browser type"); } } public enum Browsers { CHROME, FIREFOX, IE32, IE64; } 

... and then call it like ...

 WebDriver driver = startDriver(Browsers.FIREFOX); driver.get("http://www.google.com"); 

and depending on which browser you specify, this browser will be launched and go to google.com.

+15
source

WebDriver is the interface, and ChromeDriver is the class that implements the WebDriver interface. In fact, ChromeDriver extends RemoteWebDriver, which implements WebDriver. To add Every WebDriver, for example ChromeDriver, FirefoxDriver, EdgeDriver must implement WebDriver.

Below are the signatures of the ChromeDriver and RemoteDriver classes

 public class ChromeDriver extends RemoteWebDriver implements LocationContext, WebStorage {} public class RemoteWebDriver implements WebDriver, JavascriptExecutor, FindsById, FindsByClassName, FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, HasInputDevices, HasCapabilities, TakesScreenshot {} 
+14
source

WebDriver is an interface

ChromeDriver is an implementation of the WebDriver interface.

https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

There is no difference in use:

 ChromeDriver driver = new ChromeDriver(); 

or

 WebDriver driver = new ChromeDriver(); 
0
source

This may be the easiest point:

  • ChromeDriver is for the Chrome browser only.
  • WebDriver is global for all browsers
0
source

All Articles