1

I have seen almost everybody using the statement WebDriver driver=new FirefoxDriver(); here we have created an instance of FirefoxDriver class having type as Webdriver; What if i directly create an instance of FirefoxDriver as FirefoxDriver driver = new FirefoxDriver(); I have gone through many discussion where it is said that Webdriver is an interface. I know what interface is and how it works. I want to know if FirefoxDriver driver = new FirefoxDriver(); is correct when i know that Firefox is the only browser i am gonna use in my selenium script?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
iAutomate
  • 135
  • 2
  • 8
  • 1
    It is correct if you want to use a `FirefoxDriver` specifically, for example to access firefox-specific methods. If you just want to access a `WebDriver` generally (for example you want the same tests to run against Firefox, Chrome etc - perhaps not now, but in the future maybe), use `WebDriver`. – Andy Turner Apr 24 '18 at 08:26

1 Answers1

1

As you mentioned in your question that know that Firefox is the only browser you are gonna use in your selenium script then there is no constraint in using the following line of code :

FirefoxDriver driver = new FirefoxDriver();

Here you can find a detailed discussion on What is the difference between ChromeDriver and WebDriver in selenium?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352