operaprestodriver
operaprestodriver copied to clipboard
Support for entire page screenshot
Hi,
The screenshotting functionality seems to be broken. It gives the screenshot of the whole desktop instead of just the webpage inside the browser.
Here is the code i'm using to test this:
WebDriver driver = new OperaDriver(); driver.get("http://news.google.com"); ScreenShotReply scr = ((OperaDriver) driver).saveScreenshot(0); FileUtils.writeByteArrayToFile(new File("c:\temp\screenshot.png"), scr.getPng());
In my experience, it is best supported in FirefoxDriver. So, it would be nice to have it work the same way in OperaDriver too. Also, it would be great if opera screenshotting mechanism would follow the standard WebDriver TakesScreenshot interface so that it can be interoperable with other webdrivers as well.
Thanks, Shauvik
This is intentional. Internally we run Opera in fullscreen mode, and the screenshots are taken with the OperaLauncher program so that we can capture the output of plugins such as Flash.
To get a screenshot of the page it would be best to use driver.findElementByTag("body").saveScreenshot(0);
I'll look into implementing the TakesScreenshot interface.
Hi Stuart,
Thanks for your reply. This is how i got this to work for small pages:
ScreenShotReply scr = ((OperaWebElement) ((OperaDriver)driver).findElementByTagName("body")).saveScreenshot(0);
FileUtils.writeByteArrayToFile(new File("c:\\temp\\screenshot.png"), scr.getPng());
For large pages, the part outside the viewport is black. http://www.flickr.com/photos/63041483@N04/5833632246/in/photostream
I get the same problem with IEDriver but comes out properly with FirefoxDriver.
BTW, for other webdrivers, this is how one would do it using TakesScreenshot:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\temp\\screenshot.png"));
Looks like IEDriver also has similar problems on 32bit machines. http://groups.google.com/group/selenium-users/browse_thread/thread/8772c49884b3f2e8#
Hi, implementing the Interface is actually quite easy. I think that for consistency (compared with the other drivers) the interface should be implemented, so far i am using the following custom driver which works for me:
public class CustomOperaDriver extends OperaDriver implements TakesScreenshot {
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
final ScreenShotReply scr = ((OperaWebElement) findElementByTagName("body")).saveScreenshot(0);
String base64Image = null;
try {
base64Image = new String(Base64.encodeBase64(scr.getPng()), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new WebDriverException("Could not convert image to base64!", e);
}
return target.convertFromBase64Png(base64Image);
}
}
Added known issue note about this to the README: 313c726830