Discussion:
[selenium-users] Can anyone tell whether taking screenshot using selenium(casting takesScreenshot type to driver inst
Karthik Deepan
2018-11-28 11:19:00 UTC
Permalink
Can anyone tell whether taking screenshot using selenium(casting
takesScreenshot type to driver instance) is up casting or down casting?
<https://stackoverflow.com/questions/53493356/can-anyone-tell-whether-taking-screenshot-using-seleniumcasting-takesscreenshot>

WebDriver driver = new FirefoxDriver();

driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/30991710-70e4-4a01-8484-ca867895a799%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
connect2tech
2018-12-01 18:53:19 UTC
Permalink
It is downcasting.

If you look at source code of FirefoxDriver.

public class FirefoxDriver extends RemoteWebDriver {

}

*and*

public class RemoteWebDriver implements WebDriver, JavascriptExecutor,
FindsById, FindsByClassName, FindsByLinkText, FindsByName,
FindsByCssSelector, FindsByTagName, FindsByXPath,
HasInputDevices, HasCapabilities, Interactive, TakesScreenshot {
}


Regards,
~NC
https://goo.gl/DEYjrg



On Wednesday, November 28, 2018 at 11:42:15 PM UTC+5:30, Karthik Deepan
Post by Karthik Deepan
Can anyone tell whether taking screenshot using selenium(casting
takesScreenshot type to driver instance) is up casting or down casting?
<https://stackoverflow.com/questions/53493356/can-anyone-tell-whether-taking-screenshot-using-seleniumcasting-takesscreenshot>
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4100b1fd-238c-47e9-a377-fb68e06ec782%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
j***@gmail.com
2018-12-01 15:05:34 UTC
Permalink
Refer following link for Classes and Interfaces hierarchy in selenium
: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/TakesScreenshot.html

The answer lies in whether you are up casting browser driver class object
to WebDriver.

If you are writing -> WebDriver driver = new ChromeDriver() [Which is up
casting your browser class object to WebDriver]
you need to down cast the object to use the method getScreenShotAs of
Interface TakesScreenshot.
Post by Karthik Deepan
Can anyone tell whether taking screenshot using selenium(casting
takesScreenshot type to driver instance) is up casting or down casting?
<https://stackoverflow.com/questions/53493356/can-anyone-tell-whether-taking-screenshot-using-seleniumcasting-takesscreenshot>
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/835fb993-2ae1-493f-afcd-fcfafd6e2a1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...