why we assign firefoxdriver instance to webdriver

前端 未结 8 1843
时光说笑
时光说笑 2021-02-06 16:52

I am novice to Java or Selenium.

I just need help to understand one basic question.

Why we assign firefoxdriver instance to WebDriver? WebDriver driver=new Firef

8条回答
  •  忘掉有多难
    2021-02-06 17:18

    WebDriver is an interface and FirefoxDriver is a class which implements this WebDriver contract. See Selenium doc enter link description here

    Now we can create a reference variable of an interface but we can't instantiate any interface since it is just a contract to be implemented.But we can assign the instance of a class (In this case FirefoxDriver ) to its Parents(WebDriver).

    We can assign child classes to its parents(It may be a class or an interface to which it extends/implements).

    Now The reason behind doing WebDriver driver=new FirefoxDriver() is just to create an abstraction to the client(Java Program) because you can use Any Driver class according to browser.

提交回复
热议问题