user1369099
user1369099

Reputation: 21

Difference between WebDriver and FirefoxDriver

I am completely new to Selenium WebDriver. Can anyone please tell me what is the difference between these two lines?

WebDriver driver = new FirefoxDriver();

and

FirefoxDriver d = new FirefoxDriver();

Both launch the Firefox browser. So Why we always write the first line instead of 2nd line?

Upvotes: 1

Views: 8080

Answers (2)

Purus
Purus

Reputation: 5799

WebDriver is an interface.

FirefoxDriver is the implementation.

To understand better, please do read docs on Java Interface.

Upvotes: 7

Uday
Uday

Reputation: 1484

This is what is called "Static and Dynamic Binding in Java".

You can google it with above words, you will get hell lot of sites.

To tell you in simple terms:

class vehicle
{
 public void print(String str)
 { System.out.println("I am string "+str);}

 public void print(Integer int)
 {System.out.println("I am integer:"+int);}

 public static void main(String[] args)
 {
  vehicle obj=new vehicle();
  obj.print("Hello"); //Then it is clear that it will call first print method i.e String
 } //This is method overloading.
}

This is decided at compile time. so Static binding.

The other case is:

class vehicle
{
 void start(){System.out.println("Vehicle started");}
}
class car extends vehicle
{
 void start(){System.out.println("Car started");}
}
 public static void main(String[] args)
 {
  vehicle obj=new car();
  obj.start(); //Here it prints Car's start method and is decided at run time so dynamic binding
 }
}

} //This is method overriding

As per your question:

WebDriver driver=new FirefoxDriver()   //This is dynamic binding
FirefoxDriver driver=new FirefoxDriver()  //Kind of static binding

Upvotes: 4

Related Questions