UrbanPro
true

Learn Selenium from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why we declare WebDriver driver = new FirefoxDriver(); and not FirefoxDriver driver = new FirefoxDriver();

Srinivas K
23/11/2018 0 0

Here, List or WebDriver is an Interface - a contract or set of rules created for implementing class.
So, in Java, we cannot create an instance of an interface. ie
I cannot say List list = new List();
But classes can be instantiated. Hence,
FirefoxDriver fd= new FirefoxDriver(); and
ArrayList list=new ArrayList();
are meaningful because both are classes in Java.
Now, coming back to the same question. When we say FirefoxDriver fd= new FirefoxDriver(); or ArrayList list=new ArrayList();
It is nothing but using specific implementation. ArrayList or FirefoxDriver. If we have code like this, then in the future, if we want to switch to
other implementations of List or WebDriver then we need to modify our complete code as there is no guarantee that the rest of the code doesn't make use of methods specific to the particular class. However, if given like this:
List list = new ArrayList();
WebDriver driver = new FirefoxDriver();
It gives the flexibility to switch implementation any time with minimal rework.
For eg: changing ArrayList to LinkedList you can change the code to List list = new LinkedList(); from List list = new ArrayList();.

0 Dislike
Follow 3

Please Enter a comment

Submit

Other Lessons for You

How to toggle b/w frames in webdriver
driver.switchTo().frame() method takes one of the three possible arguments: A number - Select a frame by its (zero-based) index. A name or ID - Select a frame by its name or ID. A previously found...

Mobile APP Automation
Agenda of this artical is to come up with a solution to use only one test case and execute it on both android and iOS. Lets first focus on why we would need something like this. First Lets try to answer...

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

What is Selenium?
In simple words, Selenium automates browsers. It is a robust set of tools that supports rapid development of test automation for web-based applications. Cool Features: Works on every system,...

Selenium Web Driver commonly used method
Navigation Loading a web page in a current browser window driver.get("www.google.com") driver.navigate().to("www.google.com") driver.navigate().to("www.google.com") Move back & forward Driver.Navigate().Back() Driver.Navigate().Forward() Refresh...
X

Looking for Selenium Classes?

The best tutors for Selenium Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Selenium with the Best Tutors

The best Tutors for Selenium Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more