Skip to content

Commit

Permalink
fix: round values for element location for correct img cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
hmanchev authored Feb 17, 2020
1 parent 6f5026f commit a5d9a9f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/image/localScreenshotProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ LocalScreenshotProvider.prototype._cropScreenshot = function(browserScreenshot,
if (err) {
deferCropScreenshot.reject(new Error('Cannot crop the screenshot: ' + err));
} else {
that.logger.debug('View port in display pixels: width=' + data.width + ', height=' + data.height);
// check if the element is completely outside the view port
if (elementDimensions.left > data.width || elementDimensions.top > data.height ||
((elementDimensions.width + elementDimensions.left) < 0) ||
Expand Down Expand Up @@ -263,6 +264,11 @@ LocalScreenshotProvider.prototype._crop = function(originalImageBuffer, cropConf
var that = this;
var deferCrop = webdriver.promise.defer();

// Round values for correct calculations in cropping
cropConfig.top = Math.round(cropConfig.top);
cropConfig.left = Math.round(cropConfig.left);
cropConfig.width = Math.round(cropConfig.width);
cropConfig.height = Math.round(cropConfig.height);
that.logger.debug('Cropping the screenshot with parameters in display pixels: width=' + cropConfig.width +
', height=' + cropConfig.height + ', top=' + cropConfig.top + ', left=' + cropConfig.left);

Expand Down

0 comments on commit a5d9a9f

Please sign in to comment.