Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Improve cropping of rendered element
Browse files Browse the repository at this point in the history
Before, we would assume that the element was always rendered at x=0/y=0
coordinates and crop out the element from the screenshot based on the
height and width of the element. That wasn't a good assumption, as some
rendered components define vertical and/or horizontal margin. I noticed
that a diff for an element with `margin: 0 auto` (centered) wasn't
snapshotted correctly. That's what led me into including the x and y
position of the element as well.
  • Loading branch information
Henric Trotzig committed Apr 23, 2015
1 parent e4c1392 commit 4b9aeca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/likadan_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
# Save and crop the screenshot
driver.save_screenshot(output_file)
cropped = ChunkyPNG::Image.from_file(output_file)
cropped.crop!(0, 0, rendered['width'], rendered['height'])
cropped.crop!(rendered['left'],
rendered['top'],
rendered['width'],
rendered['height'])
cropped.save(output_file)

print "Checking \"#{current['name']}\" at #{width}px... "
Expand Down
6 changes: 6 additions & 0 deletions lib/public/likadan-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ window.likadan = {

var width = elem.offsetWidth;
var height = elem.offsetHeight;
var top = elem.offsetTop;
var left = elem.offsetLeft;

if (this.currentExample.options.snapshotEntireScreen) {
width = window.innerWidth;
height = window.innerHeight;
top = 0;
left = 0;
}
return {
name: this.currentExample.name,
width: width,
height: height,
top: top,
left: left
};
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 4b9aeca

Please sign in to comment.