![]() |
WebDriver Interface Concept |
Let's assume that we are automating a web based application, the first step which comes to mind is How could we invoke the browser? right??
Let us see how to invoke a browser with the help of Selenium WebDriver and understand the concept behind it.
What is an Interface?
- Interface is like a blueprint of class. It defines a set of methods but does not implement them.
- Classes will implement the Methods present in an interface.
OOP concept |
- Interface will create Rules To Follow structure for class where It Is Implemented. This way, If you look at the code of Interface, You can get Idea about your program business logic.
Yes, WebDriver Is an Interface
Since, WebDriver is an interface we need a Class to implement the Methods in it.
Question: What are the classes we need to implement the methods in WebDriver?
Answer: Below are all known Implementing Classes:
ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver,InternetExplorerDriver, MarionetteDriver, OperaDriver, RemoteWebDriver, SafariDriver
The question then arises: What Class should I Select?
Answer: It depends on your choice of browser in which you want to execute your test cases.
for example: If you want to execute your test cases in Firefox browser you should select FirefoxDriver Class and for Chrome browser you should select ChromeDriver Class and likewise for other browsers.
FireFox class where WebDriver Interface is implemented |
Therefore, let's write our first step to Invoke a Firefox browser keeping this concept in mind.
Steps to invoke Firefox browser:
- Choose the browser(Firefox) on which you want perform automation and select the respective class to implement WebDriver.
- Create an object for the class and assign a name to it
driver = new FirefoxDriver();
3. Reference class object to WebDriver interface.
WebDriver driver = new FirefoxDriver();
Run this code in Eclipse to invoke the Firefox browser.
Run this code in Eclipse to invoke the Firefox browser.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class First_WebdriverClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
}
}
Now we know the concept behind invoking the browser using WebDriver. Let me know in case of any issue.