2

I have created a Maven/Java project for the QA test automation of a web app. I use Selenium, JUnit and a bunch of other dependencies like AShot, which I use for taking screenshots.

I developed the project in my home computer (2013 13-inch MacBook Pro) and all was well when I run the project, the screenshots looked fine.

However, when I downloaded the project to my work computer (a 2017 13-inch MacBook Pro) I started to get cut screenshots. I would only see half of the screen in the screenshots. Very weird. For reference, this is what the cut screenshot looks like:

screenshot cut in half

I tried setting the dimensions and getting them at different points of the test to see if they were working. The only difference was that I got more white before the actual screenshot.

Now, I had had a similar issue in the past with this same computer but I fixed it by giving fix dimensions to the screen. The only difference from when I tested then is that I didn't have a second screen set up at the time.

I tested the project on some friends' computers and it also worked correctly there too, the screenshots didn't look cut.

At that point I wondered if it was about the differences in our set-ups, which were:

  • me without the issue: 2013 13-inch MacBook Pro (working with and without the 32-inch second screen)
  • me with the issue: 2017 13-inch MacBook Pro (working with and without the 32-inch second screen)
  • first friend (no issue): 13-inch 2019 MacBook Pro, 27-inch screen with mirror displays arrangement
  • second friend (no issue): 16-inch MacBook Pro and working with a 32-inch second screen.

I thought that it could be the mirror displays arrangement and when I did it on the computer where I had the issue, the screenshots look alright again.

However, I still don't know understand why (since my second friend was not using the mirror displays arrangement) and what's more important, how do I avoid it in the future where I probably won't have power over the setup where my project is run?

Can anyone help me? I have not found any information about this issue anywhere.

Thank you in advance and please do let me know if you need more (or less) information.

Thank you in advance!

AnaPM
  • 51
  • 7
  • It's about `.shootingStrategy()`. I'm using it this way `Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(2000)).takeScreenshot(driver); BufferedImage image = screenshot.getImage();` without any troubles. – pburgr Sep 03 '20 at 11:19
  • Hey, first of all, thanks for your reply! My code right now is this: `AShot fullScreenshot = new AShot(); BufferedImage img = fullScreenshot.shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver).getImage();` Do you mean that I have to change 100 for 2000? Thanks again! – AnaPM Sep 03 '20 at 15:28
  • Yes, that's exactly it.The sreenhots still will be different bcs of different 'device pixel ratio'. With increasing `viewportPasting` you will be able to capture more of the page. With value 2000 it should capture whole page on all devices with 'usual' pixel ratio. – pburgr Sep 04 '20 at 06:45
  • Hi again, I have changed it to 2000, but with the same set up (the second screen and the screen of my work computer) the screenshots keep getting cropped :( – AnaPM Sep 04 '20 at 16:38
  • Check meta informations of the web page. You might need to override it -> https://stackoverflow.com/questions/24209628/how-to-override-device-pixel-ratio – pburgr Sep 07 '20 at 06:14
  • ```.shootingStrategy(ShootingStrategies.scaling(2.0f))``` add this shooting strategy. Here 2.0f is `devicePixelRatio' you can find that buy running this command in browser console ```window.devicePixelRatio;``` – Dilip Meghwal Dec 04 '21 at 05:09

0 Answers0