Why do we use the WebDriver interface instead of any specific class like FirefoxWebDriver, ChromeDriver while declaring driver?


WebDriver driver = new FirefoxDriver();

and not

FirefoxDriver driver = new FirefoxDriver();

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by (32 points)
+1 vote

A variable declared as WebDriver interface type can be assigned with the objects of  multiple class types like FirefoxDriver, ChromeDriver, InternetExplorerDriver etc. 

But we cannot assign the object of FirefoxDriver class type to a variable declared of ChromeDriver class type.

Hence at Framework level inorder to run our automation scripts on a required browser type, we can simply assign the object of required Class types to the same WebDriver interface declared variable. 

- Arun Motoori (www.TutorialsNinja.com)