What is WebDriver driver = new FirefoxDriver() in Selenium?
Mukta Sharma
Software Testing || ISTQB Certified || Certified Scrum Master-CSM || Agile Safe6 certified ||
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:
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!
Engineer+Blogger+Explorer+Traveller+Freelancer
1 年https://djtechnews.in/selenium-interview-questions-with-answers/
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!!
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!
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. ??
Technical QA Lead at Qentelli | ex- Vitech Systems Asia | ex- Ad3I(Verisk) Solutions
3 年Thank you for posting. It helps