I know that I'm not the only one to ask help on this kind of stuff but I didn't successfully found a solution for my case. Im' pretty new in NodeJS
I have a method which make md5 screenshot comparaison, it returns if the 2 images are exactly the same of not. But on iOS, I have to crop the top of the screenshot and for this I'm using a crop method method from jimp package, which is async.
So in my method I'm doing this :
export function compareImage() {
const hashReference = md5File.sync(screenshot/reference/image.png)
browser.saveScreenshot(screenshotPathScreen)
if (browser.isIOS) {
cropScreenshotTop(screenshot/screen/image.png)
}
const hashScreen = md5File.sync(screenshot/screen/image.png)
return hashReference === hashScreen
}
// crop the top of the image and re-write it
function cropScreenshotTop(imagePath: string) {
var dimensions = sizeOf(imagePath)
jimp.read(imagePath, function (err, image) {
if (err) {
throw err
}
image.crop(0, 100, dimensions.width, dimensions.height - 100).write(imagePath)
})
}
So when I'm doing this, the crop is made after the return so we check the bad file. I'm trying to wait that the crop is done before the 2 last lines of my function are execute (in the case of browser.isIOS = true). How can I do that ? Right now I've add a browser.pause(1500) in the "if" part, which is pretty ugly. Thanks a lot
(I know it can be tagged as duplicate but I've haven't find a solution for my example)