WebDriver Architecture
SearchContext is a top most interface which has only two methods names findElement() and findElements(). These methods will be abstract as SearchContext is an interface.
WebDriver is also an interface which extends SearchContext. WebDriver has many abstarct methods like get(String url), close(), quit() , getWindowHandle etc. WebDriver has nested interfaces names Window, Navigation, Timeouts etc. These nested interfaces are used to perform/group specific operation like getPosition(), back(), forward() etc.
RemoteWebDriver is a fully implemented class which implements Webdriver, JavascriptExecutor and TakesScreenshot. Fully implemented class means it defined body for all inherited methods.
Then we have browser specific driver classes like ChromeDriver(), EdgeDriver(), FirefoxDriver() etc.
Why do we upcast any browser driver class object to WebDriver?
In selenium, maximum time when we create an object of any browser driver class, we do upcast.
E.g. WebDriver driver= new FirefoxDriver();
You can launch any browser through single browser factory method
It is a good programming practice to upcast the object to maximum level possible keeping in mind that you should not loose important functionalities.
If we upcast object to SearchContext, it will not be so feasible as it has only two methods. To use other important methods, we need to do down casting.
Keeping 2nd point in mind, We can upcast till WebDriver as we are not making it difficult to use important methods because of major concept of overriding in java. So, we do not upcast to RemoteWebDriver.
Remember, there is no such mandatory rule that you need to upcast or downcast. It is just way of proper programming.
Is the FirefoxDriver a Class or an Interface?
FirefoxDriver is a Java class, and it implements the WebDriver interface.
What is the super interface of WebDriver?
SearchContext.
Comments
Post a Comment