Why do we write WebDriver driver = new FirefoxDriver(); ?

As we see, all the Selenium automation test scripts with a line –

WebDriver driver = new FirefoxDriver();
(depend on which browser do you use. To learn how can use other browsers like chrome and ie, refer below post.
Refer:  
 Working with Mozilla Firefox, google chrome and Internet Explorer in Selenium WebDriver (link))
Now, in above line, WebDriver is an interface. FirefoxDriver is a class. driver is instance. In other words, Instance of FirefoxDriver() (which is a class) is created and is stored in instance variable called “driver”.
To remember, An Interface contains empty methods that have been defined but not implemented.  These methods can be implemented by anyone.
FirefoxDriveris a class that has been written specifically for the Firefox browser. It has methods that are implemented and it can be instantiated. It can perform all functions (or methods) on the Firefox browser as defined in the interface WebDriver.

Above image best describes what we are reading in the post.
Do post your questions if you have any.

 

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories