What is WebDriver driver = new FirefoxDriver() in Selenium?
Image Source Credit: ArtofTesting/google images

What is WebDriver driver = new FirefoxDriver() in Selenium?

Hi there, have you come across this question in interviews? Have you been using the above line of code in your programming but not really sure what it means? Well, when I had started working as an automation engineer, I wanted to understand the exact meaning of each and every word in this specific line of code. So, without any further delay, let's discuss what it signifies.

Example:

package LinkedIn;

public class FirstLinkedInTestCase{

public static void main(String[] args)

{

// Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver();

Explanation:

WebDriver is an interface that is available in Selenium jar files. driver is webDriver reference variable. New is a keyword, we use to create an instance of the class. And, FireFoxDriver() is a class already existing in Selenium. So, you can import it and start using it for your test. That's it. Read slowly once again ...

But, if you run the above code, you will get an exception error. Why?

.

.

.

Because we have not imported the required below packages:

  1. import org.openqa.selenium.webDriver;
  2. import org.openqa.selenium.firefox.FirefoxDriver;

Therefore, when you write this specific line of code, it will initiate firefox browser. And, then you can perform an action as per your requirement. Example: driver.get ("https://www.google.com");

Note: In Eclipse, these packages will be automatically imported to your class, if you enable autosuggestion.

I hope it is easy to understand the context behind using the specific line of code. Please feel free to provide inputs from your side. Let's learn, share and grow together. Thank you for reading!




Kiran Singh

Immediate Joiner || Automation Tester (Selenium Cucumber BDD Framework using Java) || POM Design Pattern || Manual Tester || Rest APIs Testing || Jira || Agile Scrum Process.

2 年

Nice Explanation.. Thank you!!

Sreedevi M

Hybrid QA Engineer Manager / Officer at StateStreet | Certified Scrum Master | Pega CSA | Selenium Automation | Security & Accessibility Testing | Ex: Pega Systems

3 年

WebDriver is the interface and casting it to FirefoxDriver Class or any other browser classes like ChromeDriver, InternetExplorerDriver, PhantomJSDriver, SafariDriver etc which have the implementation of WebDriver interface methods, we will be able to perform actions in respective browsers. Hope this helps!

Jagadish Hadimani

Lead QA Engineer | Automation & API Testing | Agile & DevOps | AI in Testing | Ensuring Quality at Scale

3 年

I was expecting to read how Firefox is upcasted to Webdriver, it is missing. But rest else is on point. ??

Balaram Chalamalasetty

Technical QA Lead at Qentelli | ex- Vitech Systems Asia | ex- Ad3I(Verisk) Solutions

3 年

Thank you for posting. It helps

要查看或添加评论,请登录

Mukta Sharma的更多文章

  • What is Cloud/ cloud computing? Any real-time examples to understand it for a novice in the cloud?

    What is Cloud/ cloud computing? Any real-time examples to understand it for a novice in the cloud?

    You can consider it as a virtual remote server where you can save your data, process your data, access your data with…

  • Day 1 - New office - Activities involved, my learnings & Tips for you

    Day 1 - New office - Activities involved, my learnings & Tips for you

    I really wanted to write about my day1 at the new company. Some of you have messaged me on LinkedIn and asked me about…

  • What is SelectorsHub & its Advantages and why you should be using it?

    What is SelectorsHub & its Advantages and why you should be using it?

    SelectorsHub is making loud noise these days ( in good terms, of course) so I thought to write my own views in terms of…

    10 条评论
  • Client Server Architecture to understand API's

    Client Server Architecture to understand API's

    In order to have in-depth understanding of API’s, we first need to understand the client server architecture. So, let’s…

    20 条评论
  • Test Project 2.0

    Test Project 2.0

    Test Project 2.0 March 17, 2021 – Wednesday, the day will be remembered by many Software professionals all across the…

    9 条评论
  • What is Appium & its Architecture?

    What is Appium & its Architecture?

    Mobile testing is on boom these days. I have covered one tutorial on Mobile application testing & Types in my previous…

    11 条评论
  • What is BDD, Cucumber, Gherkin, Feature?

    What is BDD, Cucumber, Gherkin, Feature?

    We are using BDD in our projects but some of my friends and colleagues have some questions which I listed below and…

    9 条评论
  • Synchronization in Selenium

    Synchronization in Selenium

    When two or more components work together to perform any action at the same pace, the process is called…

    20 条评论
  • Mobile Application Testing & Types

    Mobile Application Testing & Types

    Many of us have heard about “Appium”, “Robotium”, “Selendroid”, “Calabash” or “Espresso” which are some of the tools…

    35 条评论
  • Challenges in Test Automation and their solutions

    Challenges in Test Automation and their solutions

    Hi Guys, Have you just started your career in Test Automation? Or if you have few years’ experience in automation like…

    12 条评论

社区洞察

其他会员也浏览了