Why we assign firefoxdriver instance to webdriver

What is the diff between following:
Webdriver driver = new FirefoxDriver();
FirefoxDriver driver = new FirefoxDriver();

Why we always assign firefoxdriver instance to webdriver?

Default Asked on February 29, 2016 in Selenium WebDriver.

You can assign any driver instance
it depends on requirement  say if you wanted to run your test cases in I.E

System.setProperty(“webdriver.ie.driver”, “D:\ToolsQA\OnlineStore\drivers\IEDriverServer.exe”);
  driver = new InternetExplorerDriver();

follow this link

for more info

on February 29, 2016.

That is just an additional level of abstraction that allows you to use WebDriver interface in your code instead of its particular implementation – FirefoxDriver. WebDriver variable may be any of available drivers. FirefoxDriver can only be a FirefoxDriver.

It just makes easier to switch between different drivers later.  If you do not need it, then no much difference for you.

on February 29, 2016.

These are right answers can you both please put them as answers so that the question can be marked as answered.

on March 2, 2016.
Add Comment
  • 1 Answer(s)

    WebDriver is an Interface
    FirefoxDriver is a class

    Although  there is no difference in functionality, we use WebDriver when we have a plan to run our script on multiple browsers by calling Webdriver interface.
    If we use FirefoxDriver than it’s like hard coding for only Firefox browser.

    So use them as accordingly.

    Default Answered on March 7, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.