cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
32 lines (31 loc) • 1.04 kB
JavaScript
import { getUnionDOMRect } from "./highlight";
const { _ } = Cypress;
// custom implementation of screenshot command to take screenshot of
// multiple elements by using union of their bounding client rectangles
Cypress.Commands.overwrite("screenshot", (originalFn, ...args) => {
const subject = args[0];
if (subject != null && subject.length > 1) {
const [_name, _options] = args.slice(1);
let o = {};
let n = undefined;
if (_.isObjectLike(_name)) {
o = _name;
n = undefined;
}
else {
n = _name;
o = _options || {};
}
const padding = _.pick(o, "padding");
const unionRect = getUnionDOMRect(subject, padding);
const clip = {
x: unionRect.left,
y: unionRect.top,
width: unionRect.width,
height: unionRect.height,
};
o.clip = clip;
return originalFn(undefined, n ?? o, n ? o : undefined);
}
return originalFn(...args);
});