Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for entire page screenshot #5

Open
shauvik opened this issue Jun 13, 2011 · 5 comments
Open

Support for entire page screenshot #5

shauvik opened this issue Jun 13, 2011 · 5 comments

Comments

@shauvik
Copy link

shauvik commented Jun 13, 2011

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

@Stuk
Copy link
Contributor

Stuk commented Jun 14, 2011

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.

@shauvik
Copy link
Author

shauvik commented Jun 14, 2011

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"));

@shauvik
Copy link
Author

shauvik commented Jun 14, 2011

Looks like IEDriver also has similar problems on 32bit machines.
http://groups.google.com/group/selenium-users/browse_thread/thread/8772c49884b3f2e8#

@andywuest
Copy link

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);
  }

}

@andreastt
Copy link
Contributor

Added known issue note about this to the README: 313c726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants