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

Screenshot only capturing upper-left corner of the visible window #104

Closed
1hella opened this issue Jul 21, 2017 · 5 comments
Closed

Screenshot only capturing upper-left corner of the visible window #104

1hella opened this issue Jul 21, 2017 · 5 comments

Comments

@1hella
Copy link
Contributor

1hella commented Jul 21, 2017

I'm having trouble capturing the entire page. It appears to only be capturing the top-left corner of the page.

webDriver.navigate().to("https://www.reddit.com/");
				
String screenshotDirectoryPath = "target/site/screenshots/test/";
new File(screenshotDirectoryPath).mkdirs();
		
String outputFileName = "reddit.jpg";
File outputFile = new File(screenshotDirectoryPath + "/" + outputFileName);

Screenshot takeScreenshot = new AShot()
		.shootingStrategy(ShootingStrategies.viewportPasting(100))
		.takeScreenshot(Browser.getDriver());
BufferedImage image = takeScreenshot.getImage();

try {
	ImageIO.write(image, "jpg", outputFile);
} catch (IOException e1) {
	System.out.println("Unable to save screenshot");
	e1.printStackTrace();
}

Here's the screenshot I get with this code:
reddit

And here's a comparable screenshot I got using a chrome plugin:
download

Specs:

  • Google Chrome 59.0.3071.115 (Official Build) (64-bit)
  • Chromedriver 2.29
  • Mac OS Sierra 10.12.5
  • 2880 x 1800 resolution
  • Selenium 3.4.0
  • Java 8
@pazone
Copy link
Owner

pazone commented Jul 21, 2017

@1hella Thanks for report! I guess it is related to #96

@1hella
Copy link
Contributor Author

1hella commented Jul 21, 2017

No problem. Is there anything I can do to help?

@pazone
Copy link
Owner

pazone commented Jul 25, 2017

@1hella Sorry for confusing you. The problem is that your screen DPR is 2 (Retina display). Taken image is 4 times bigger than it actually is. We have workaround for it. Take a look to ShootingStrategies factory. You can find viewportRetina method there. That's exactly you are looking for.

@1hella
Copy link
Contributor Author

1hella commented Jul 25, 2017

@pazone Got it, thanks.

Changing from .shootingStrategy(ShootingStrategies.viewportPasting(100)) to .shootingStrategy(ShootingStrategies.viewportRetina(100, 0, 0, 2)) works for me.

@TariqueKhanANX
Copy link

TariqueKhanANX commented Jul 18, 2018

image size got reduced and only capturing the current viewport in MacOS High Sierra (Chrome and Firefox)
final Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportRetina(100, 0, 0, 2)).takeScreenshot(driver);

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

3 participants