Why WebDriver driver?
As we proceed further to the webpage automation, the important questions arises in mind why always WebDriver driver = new ChromeDriver() / FireFoxdriver() ... and why not to use
WebDriver driver = new WebDriver(), or ChromeDriver driver = new ChromeDriver().
1. Since we can not create object of an Interface as it does not have any constructor, the possiblity WebDriver driver = new WebDriver() is not valid since WebDriver is an interface.
2. If we decided to use ChromeDriver driver = new ChromeDriver() then our script will only capable of launching Chrome driver and we will not able to handle the multi browser.
Since we can not create object of an interface, JAVA still allows to use abstract methods in it. How?
The answer is the class which implements an interface will help up to create an object.
As ChromeDriver()/ FireFoxDriver()/ IEdriver classes(s) implements Webdriver interface, it is possible to create object of WebDriver with reference of these classes. Hence , while writing code we always do WebDriver driver = new ChromeDriver() / FireFoxdriver() ...
WebDriver driver = new WebDriver(), or ChromeDriver driver = new ChromeDriver().
1. Since we can not create object of an Interface as it does not have any constructor, the possiblity WebDriver driver = new WebDriver() is not valid since WebDriver is an interface.
2. If we decided to use ChromeDriver driver = new ChromeDriver() then our script will only capable of launching Chrome driver and we will not able to handle the multi browser.
Since we can not create object of an interface, JAVA still allows to use abstract methods in it. How?
The answer is the class which implements an interface will help up to create an object.
As ChromeDriver()/ FireFoxDriver()/ IEdriver classes(s) implements Webdriver interface, it is possible to create object of WebDriver with reference of these classes. Hence , while writing code we always do WebDriver driver = new ChromeDriver() / FireFoxdriver() ...
Hi Pranesh,
ReplyDeleteIn the below point as mentioned by you, shouldn't it be class(es) instead of method(S)
'As ChromeDriver()/ FireFoxDriver()/ IEdriver method(s) implements Webdriver interface'
Thank you for pointing this out.. it is corrected
Delete