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

Open 1 Answers 89 Views
0 1
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();

1 Answer


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)

answered by (31 points)

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.

We have resolved 1.2k+ Software Testing queries!

Top Contributors