Skip to content

Commit

Permalink
feat: Screenshooting of web elements (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 9, 2024
1 parent 0c4ca8b commit b12e4dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/commands/screenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ export default {
el = util.unwrapElement(el);
if (this.isWebContext()) {
const atomsElement = this.getAtomsElement(el);
return await this.executeAtom('getElementScreenshot', [atomsElement]);
const {width, height} = await this.executeAtom('get_size', [atomsElement]);
if (!width || !height) {
throw new errors.UnableToCaptureScreen('Cannot take a screenshot of a zero-size element');
}
const {x, y} = await this.executeAtom('get_top_left_coordinates', [atomsElement]);
return await (/** @type {import('appium-remote-debugger').RemoteDebugger} */ (this.remote))
.captureScreenshot({rect: {x, y, width, height}});
}

const data = await this.proxyCommand(`/element/${el}/screenshot`, 'GET');
if (!_.isString(data)) {
this.log.errorAndThrow(
`Unable to take a screenshot of the element ${el}. WDA returned '${JSON.stringify(data)}'`,
throw new errors.UnableToCaptureScreen(
`Unable to take an element screenshot. WDA returned: ${JSON.stringify(data)}`,
);
}
return data;
Expand Down

0 comments on commit b12e4dd

Please sign in to comment.