SELENIUM BASICS:

  • What is Automation Testing - Advantages & Types of Tools
  • What is Selenium IDE, Selenium RC, Selenium WebDriver, Selenium Grid?
  • Selenium IDE, Firebug & Firepath Installation

  • SELENIUM WEBDRIVER:

  • Selenium WebDriver Architecture
  • Selenium Installation
  • Challenges and Limitations of Selenium
  • First Selenium WebDriver Script
  • Working with Firefox Browser
  • Solution - Failed To Launch Browser Using Selenium WebDriver
  • Working with Chrome Browser
  • Working with IE Browser
  • Difference Between FindElement & FindElements
  • Install Firebug, Fire path and other add on for Selenium
  • Locators in Selenium
  • Dynamic Xpath
  • Dynamic CSS
  • Handle drop-downs
  • How to work with file upload
  • Handle Alerts & Popups
  • Handle Multiple Windows
  • Mouse Hover event in Selenium
  • Right Click
  • Double Click
  • Drag and Drop
  • Capture Screenshots in Selenium
  • Parameterization
  • Synchronization
  • Implicit Wait, Explicit Wait and Fluent Wait in Selenium
  • Implicit Waits
  • Explicit WebDriver Waits
  • Fluent Wait In Selenium
  • Apache POI
  • How To Read Data From Excel File
  • How To Write Data In Excel File
  • Database Testing Using MSSQL
  • Database Testing Using MySQL
  • Database Testing Using DB2
  • Handle Ajax Call in Selenium
  • Listeners in Selenium
  • Handling JavaScript in Selenium
  • Stale Element Reference Exception in Selenium
  • Integrate Sikuli with Selenium
  • Headless Browser Testing 
  • Headless Browser Testing using HtmlUnitDriver
  • Headless Browser Testing using PhanthomJSDriver

  • TESTNG:

  • TestNG Installation
  • TestNG Complete Tutorial

  • REPORTS:

  • Extent Reports Introduction
  • Extent Reports Generation
  • Capturing Screenshots & Including In Extent Reports
  • Extent Reports Version 4

  • BUILD & CONTINUOUS INTEGRATION TOOLS:

  • ANT Build Tool - How To Download & Install
  • Maven Build Tool - How To Download & Install
  • Creating Maven Selenium Project
  • GIT Integration with Selenium
  • Jenkins - How To Download & Install
  • Jenkins - Executing TestNG Scripts
  • Jenkins - Generating Reports After Test Execution
  • Jenkins - Executing Maven Project
  • Create build and Execute build for nightly execution
  • Send Email report based on build Status
  • Selenium Continuous Integration with Jenkins [Selenium – Maven – Git – Jenkins] – Step By Step Guide

  • CROSS BROWSER TESTING:

  • Running Selenium Tests On BrowserStack
  • Kobiton - Mobile Testing Platform with Real Devices

  • MOBILE TESTING:

  • Mobile Testing Platform with Real Devices

  • AUTOMATION FRAMEWORKS:

  • What is Framework & Types of Framework
  • Page Object Model Design Pattern
  • Data Driven Framework
  • How to explain Test Automation Framework or Selenium Automation Framework Architecture In Interview

  • API Testing:

  • Learn API Testing
  • Postman Tutorial (API Testing with Postman)

  • INTERVIEW QUESTIONS:

  • Test Automation Framework Interview Questions
  • Selenium Interview Questions
  • TestNG Interview Questions
  • Java Interview Questions
  • Python Interview Questions
  • API Testing Interview Questions

  • SAMPLE RESUME:

  • Automation Tester Resume
  • WebDriver driver = new FirefoxDriver() – Why we write in Selenium Scripts

    In this post, we see why in Selenium scripts we write WebDriver driver = new FirefoxDriver(). Many students asked this question and I would like to share few points here.

    Why WebDriver driver = new FirefoxDriver();

    We are going to discuss following points in this post.

    1. Why not WebDriver driver = new WebDriver()
    2. Why we wont prefer FirefoxDriver driver = new FirefoxDriver()
    3. Why WebDriver driver = new FirefoxDriver()
    4. What is RemoteWebDriver and where we use it

    Java Tutorial for Selenium Testers

    Before going into the details lets see the below image.

    Why WebDriver driver = new FirefoxDriver();

    Following are the few points based on the above image.

    • SearchContext is the super most interface in selenium, which is extended by another interface called WebDriver.
    • All the abstract methods of SearchContext and WebDriver interfaces are implemented in RemoteWebDriver class.
    • All the browser related classes such as FirefoxDriver, ChromeDriver etc., extends the RemoteWebdriver class.

    Must learn: Selenium WebDriver Architecture

    WebDriver defines common methods which all browser classes (such as Firefox, Chrome etc.,) use. All these class methods are derived from WebDriver interface.

    All the abstract methods of both the interfaces are implemented in RemoteWebDriver class which is extended by browser classes such as Firefox Driver, Chrome Driver etc.

    Let’s see why can’t we use the following statement.

    WebDriver driver = new WebDriver();

    We cannot write our code like this because we cannot create Object of an Interface. WebDriver is an interface.

    But we can use any of the following statements in our script

    FirefoxDriver driver = new FirefoxDriver();

    or

    WebDriver driver = new FirefoxDriver();

    Let’s see both of them in detail.

    FirefoxDriver driver = new FirefoxDriver();

    The FirefoxDriver instance which gets created based on above statement will be only able to invoke and act on the methods implemented by FirefoxDriver and supported by Firefox Browser only. We know that FirefoxDriver is a class and it implements all the methods of WebDriver interface. Using this statement, we can run our scripts only on Firefox Browser.

    To act with other browsers we have to specifically create individual objects as below:

    ChromeDriver driver = new ChromeDriver();

    InternetExplorerDriver driver = new InternetExplorerDriver();

    We don’t just run our scripts only on single browser. We use multiple browsers for Cross Browser Compatibility.  We need the flexibility to use other browsers like ChromeDriver() to run on Chrome Browser and InternetExplorerDriver() to run on IE Browser and so on.

    So, once you initiate a Firefox browser using FirefoxDriver driver = new FirefoxDriver(); same object cannot be used to initiate Chrome Browser (you have to rename it)

    ChromeDriver driver = new ChromeDriver();

    To solve this we use “Webdriver driver = new FirefoxDriver();

    Lets see this now.

    WebDriver driver = new FirefoxDriver();

    We can create Object of a class FirefoxDriver by taking reference of an interface (WebDriver). In this case, we can call implemented methods of WebDriver interface.

    As per the above statement, we are creating an instance of the WebDriver interface and casting it to FirefoxDriver Class. All other Browser Drivers like ChromeDriver, InternetExplorerDriver, PhantomJSDriver, SafariDriver etc implemented the WebDriver interface (actually the RemoteWebDriver class implements WebDriver Interface and the Browser Drivers extends RemoteWebDriver). Based on this statement, you can assign Firefox driver and run the script in Firefox browser (any browser depends on your choice).

    We will see RemoteWebDriver in later section below.

    If you define driver as a WebDriver, switching will be very easy. If we use this statement in our script then the WebDriver driver can implement any browser. Every browser driver class implements WebDriver interface and we can get all the methods. It helps you when you do testing on multiple browsers.

    Example:

    WebDriver driver = new FirefoxDriver();
    driver.quit();
    driver = new ChromeDriver();

    WebDriver is an interface and all the methods which are declared in Webdriver interface are implemented by respective driver class. But if we do upcasting,we can run the scripts in any browser .i.e running the same automation scripts in different browsers to achieve Runtime Polymorphism.

    WebDriver driver = new FirefoxDriver();

    Here, WebDriver is an interface, driver is a reference variable, FirefoxDriver() is a Constructor, new is a keyword, and new FirefoxDriver() is an Object.

    General information: Selenium WebDriver is an Interface which contains different methods (eg., get(), getTitle(), close() etc., ). All the third party Browser vendors implement these methods in addition to their browser specific methods. This would in-turn help the end-users to use the exposed APIs to write a common code and implement the functionalities across all the available Browsers without any change. Selenium developers don’t know how all these browsers work. So Selenium developers just declare methods whatever they required and leave the implementation part to the browser developers.

    Difference between WebDriver and RemoteWebDriver:

    As per Java’s interface concept, Interface contains only Method’s signature and it doesn’t contain the Method’s definitions.

    Check this post to know the difference between Method Declaration and Method Definition.

    WebDriver is the Interface which contains all the Selenium Method signatures (Eg findElement(),switchTo(),get() etc.) where as definition for those methods are in RemoteWedDriver Class.

    If we want to run our automation scripts on the local machine’s browser then we can use any class (such as Firefoxdriver, iedriver, chromedriver, htmlunitdriver) except RemoteWebDriver. WebDriver will start up a web browser on the computer where the code instantiates it.

    If we want to run our automation scripts on the remote machine’s browser then we use RemoteWebDriver. RemoteWebDriver requires the Selenium Standalone Server to be running but to use other drivers Selenium Standalone Server is not required.

    If you want to work with Grid then you have to stick with RemoteWebDriver. The only requirement is that for a RemoteWebDriver to work, you would always have to have it pointing to the URL of a Grid.

    If you are using any of the drivers other than RemoteWebDriver then the communication will happen on the local machine’s browser.

    Ex: Webdriver driver = new FirefoxDriver();

    driver will access Firefox on the local machine, directly.

    If we use RemoteWebDriver then we have to mention where the Selenium Server is located and which web browser you want to use.

    Ex: WebDriver driver = new RemoteWebDriver(new URL Desired capabilities.firefox());

    We can use RemoteWebDriver the same way we would use WebDriver locally. The primary difference is that remote webdriver needs to be configured so that it can run your tests on a remote machine.

    WebDriver is an interface that you should be using throughout your tests. RemoteWebDriver is a concrete implementation of that interface. In general, its always a good idea to code against interfaces wherever possible.

    Hope you are clear. If you like this post, don’t forgot to share it.

    You may also like this:

    Popular Interview Questions

    Why WebDriver driver = new FirefoxDriver();

    Get our latest blog posts delivered to your inbox

    Subscribe and get popular blog posts about software testing industry.

    Rajkumar

    2 thoughts on “WebDriver driver = new FirefoxDriver() – Why we write in Selenium Scripts”

      • Hi Ramani, Yes FirefoxDriver is a class. Even I mentioned that in my post. Also check why I mentioned FirefoxDriver is a constructor. Hope you didnt go through the complete post. Please read it again. If you still have any queries, please comment here.

    Leave a Comment

    Share via
    Copy link
    Powered by Social Snap