octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.37k stars 961 forks source link

Screen capture is broken when passing width and height params on macOS #488

Closed will123195 closed 5 years ago

will123195 commented 5 years ago

Summary

Screen capture is not working as expected when width and height are provided.

// working as expected
robot.screen.capture()

// NOT working as expected
robot.screen.capture(0, 0, 200, 200) 

Expected Behavior

robot.screen.capture(x, y, w, h) should return the correct image.

Current Behavior

Cropped screen captures are incorrect, for example:

screen

Steps to Reproduce (for bugs)

I would expect this test case to pass, but it is currently failing:

it('Get a cropped bitmap and make sure the colorAt works as expected', function() {
  var x = 15;
  var y = 35;
  var w = 10;
  var h = 10;
  var full = robot.screen.capture();
  var crop = robot.screen.capture(x, y, w, h);
  // check that each pixel in the crop matches the corresponding pixel in the full screen capture
  for (var i = 0; i < w; i++) {
    for (var j = 0; j < h; j++) {
      var fullPixelColor = full.colorAt(x + i, y + j);
      var cropPixelColor = crop.colorAt(i, j);
      expect(fullPixelColor).toEqual(cropPixelColor);
    }
  }
});

Your Environment

will123195 commented 5 years ago

Oops, there must be a mistake in my test case.

The following gist confirms this is not a valid bug: https://gist.github.com/will123195/6d77d8a7152ed13ca44f3e52ed2a20b4