Selenium WebDriver is a collection of open source APIs which are used to automate the testing of a web application. Description: Selenium WebDriver tool is used to automate web application testing to verify that it works as expected. It supports many browsers such as Firefox, Chrome, IE, and Safari.
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.
Please subscribe the channel and visit to www.ananyatech.net & write at [email protected] for more details.
Facebook page: / ananyasoftwaretechnologies