If you're looking to crop an image using Intern, there isn't a direct built-in method for it. The takeScreenshot
function in Intern fetches the entire page's screenshot as a base-64 encoded PNG from Selenium's screenshot service. Intern then converts this into a Node buffer before providing it to the user.
To achieve image cropping, you'll need to utilize an external library or tool like png-crop (although my experience with it is limited). Below is some sample code (not tested):
var image;
var size;
var position;
return this.remote
// ...
.takeScreenshot()
.then(function (imageBuffer) {
image = imageBuffer;
})
.findById('element')
.getSize()
.then(function (elementSize) {
size = elementSize;
})
.getPosition()
.then(function (elementPosition) {
position = elementPosition;
})
.then(function () {
// assuming png-crop is loaded as PNGCrop
var config = {
width: size.width,
height: size.height,
top: position.y,
left: position.x
};
// Need to return a Promise since PNGCrop.crop is asynchronous
return new Promise(function (resolve, reject) {
PNGCrop.crop(image, 'cropped.png', config, function (err) {
if (err) {
reject(err);
}
else {
resolve();
}
});
});
})