e2ed
Version:
E2E testing framework over Playwright
29 lines (28 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.takeElementScreenshot = void 0;
const node_path_1 = require("node:path");
const internal_1 = require("../constants/internal");
const step_1 = require("../step");
const screenshot_1 = require("../utils/screenshot");
/**
* Takes a screenshot of the specified element.
*/
const takeElementScreenshot = async (selector, options = {}) => {
const { path: pathToScreenshot, ...optionsWithoutPath } = options;
const { timeout } = options;
await (0, step_1.step)('Take a screenshot of the element', async () => {
if (pathToScreenshot !== undefined) {
// eslint-disable-next-line no-param-reassign
options.path = (0, node_path_1.join)(internal_1.SCREENSHOTS_DIRECTORY_PATH, pathToScreenshot);
}
const screenshot = await selector.getPlaywrightLocator().screenshot(options);
const dimensions = (0, screenshot_1.getDimensionsString)((0, screenshot_1.getPngDimensions)(screenshot));
return { dimensions };
}, {
payload: { pathToScreenshot, ...optionsWithoutPath, selector },
...(timeout !== undefined ? { timeout: timeout + internal_1.ADDITIONAL_STEP_TIMEOUT } : undefined),
type: 5 /* LogEventType.InternalAction */,
});
};
exports.takeElementScreenshot = takeElementScreenshot;