Reason to upcast the browser related child class to WebDriver and not RemoteWebDriver class
(RemoteWebDriver being the super most class in Selenium):
Upcasting Example :
WebDriver driver = new FirefoxDriver();
- Converting a child class object to super type is called Upcasting.
- In Selenium , we use upcasting so that we can execute the same script on any browser.
- In Selenium , we can upcast browser object to RemoteWebDriver, WebDriver,
TakesScreenshot , JavascriptExecutor etc, but a standard practice is to upcast to
WebDriver interface.
- This is as per the Selenium coding standard set by the Selenium community. As a
testimonial, navigate to the below Selenium community site and check for the text as
mentioned in the image below.
Url - http://www.SELENIUMhq.org/projects/webdriver/
Upcasting in Selenium
WebDriver driver = new FirefoxDriver();
Explain the above statement.
1. WebDriver is an interface in Selenium that extends the supermost interface called
SearchContext.
2. driver is the upcasted object of WebDriver interface reference variable.
3. “=” is an assignment operator.
4. new is a keyword using which object of the FirefoxDriver class is created.
5. FirefoxDriver() is the constructor of FirefoxDriver class which initializes the object and it
will also launch the firefox browser.
Upcasting Example :
WebDriver driver = new FirefoxDriver();
- Converting a child class object to super type is called Upcasting.
- In Selenium , we use upcasting so that we can execute the same script on any browser.
- In Selenium , we can upcast browser object to RemoteWebDriver, WebDriver,
TakesScreenshot , JavascriptExecutor etc, but a standard practice is to upcast to
WebDriver interface.
- This is as per the Selenium coding standard set by the Selenium community. As a
testimonial, navigate to the below Selenium community site and check for the text as
mentioned in the image below.
Url - http://www.SELENIUMhq.org/projects/webdriver/
Upcasting in Selenium
WebDriver driver = new FirefoxDriver();
Explain the above statement.
1. WebDriver is an interface in Selenium that extends the supermost interface called
SearchContext.
2. driver is the upcasted object of WebDriver interface reference variable.
3. “=” is an assignment operator.
4. new is a keyword using which object of the FirefoxDriver class is created.
5. FirefoxDriver() is the constructor of FirefoxDriver class which initializes the object and it
will also launch the firefox browser.
0 Comments