Tuesday 7 January 2014

Why we refer Firefox driver to the web driver inheritance

7.   Why we refer Firefox driver to the web driver inheritance. 

web Driver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...) etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver, IEDriver, Andriod driver etc) to it.
Ex :
WebDriver driver = new FireFoxDriver();-----------(1)
If we are using (1) we can do the same thing by using
FireFoxDriver driver = new FireFoxDriver();---------(2)
We can use (1) and (2) for same purpose but if we want to switch to another browser in same program
then again we have to create the object of other class as for example
CromeDriver driver = new CromeDriver();.
creating object of several class is not good. So we create the reference of WebDriver and
we assign the objects of another class as for example
WebDriver driver; // it is created only one time in the program
driver = new FireFoxDriver();// any where in the program
driver = new CromeDriver(); // any where in the program


13 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thank you for the explanation Ruchi. I am new to Selenium and from what I understand here... WebDriver is an interface which implements classes like FirefoxDriver, chromedriver, etc right? Please correct me if I'm wrong!

    [http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html]

    ReplyDelete
  3. I believe WebDriver is a Parent class not the interface.C

    ReplyDelete
    Replies
    1. Webdriver is a interface.

      Delete
  4. Good Explanation !!
    But what is the need of switch browser in a single class ?
    User can open the same browser in new window right ?

    Please explain.

    ReplyDelete
    Replies
    1. to do compatibility testing in different browsers ,we can test same scenario in different browsers..

      Delete
  5. FirefoxDriver,ChromeDriver,,,,etc classes implements the WebDriver interface

    ReplyDelete
  6. FirefoxDriver,ChromeDriver...etc classed implements the WebDriver interface

    ReplyDelete
  7. in the above example we are creating the objects for many classes .like
    new chromeDriver(),new FirefoxDriver(),are the object creation.i think you have to say creating many references (or) object variables is not so good so that is the reason we use web driver reference.

    ReplyDelete