Last active
June 11, 2017 22:16
-
-
Save chrvadala/42a7065b807461e6f39ca8a59a2625e6 to your computer and use it in GitHub Desktop.
nightwatch usefull commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
const Jimp = require('jimp'); | |
exports.command = function (selector, fileName) { | |
this.perform((client, done) => { | |
let width, height, x, y; | |
client | |
.saveScreenshot(fileName) | |
.getLocationInView(selector, position => { | |
({x, y} = position.value); | |
}) | |
.getElementSize(selector, size => { | |
({width, height} = size.value) | |
}) | |
.perform((client, done) => { | |
Jimp | |
.read(fileName, function (err, image) { | |
image | |
.crop(x, y, width, height) | |
.write(fileName, () => { | |
done(); | |
}) | |
}) | |
}); | |
done() | |
}); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment