Skip to content

Instantly share code, notes, and snippets.

@chrvadala
Last active June 11, 2017 22:16
Show Gist options
  • Save chrvadala/42a7065b807461e6f39ca8a59a2625e6 to your computer and use it in GitHub Desktop.
Save chrvadala/42a7065b807461e6f39ca8a59a2625e6 to your computer and use it in GitHub Desktop.
nightwatch usefull commands
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