e2ed
Version:
E2E testing framework over Playwright
31 lines (30 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.takeScreenshot = void 0;
const node_path_1 = require("node:path");
const internal_1 = require("../constants/internal");
const step_1 = require("../step");
const useContext_1 = require("../useContext");
const screenshot_1 = require("../utils/screenshot");
/**
* Takes a screenshot of the tested page.
*/
const takeScreenshot = async (options = {}) => {
const { path: pathToScreenshot, ...optionsWithoutPath } = options;
const { timeout } = options;
await (0, step_1.step)('Take a screenshot of the page', 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 page = (0, useContext_1.getPlaywrightPage)();
const screenshot = await page.screenshot(options);
const dimensions = (0, screenshot_1.getDimensionsString)((0, screenshot_1.getPngDimensions)(screenshot));
return { dimensions };
}, {
payload: { pathToScreenshot, ...optionsWithoutPath },
...(timeout !== undefined ? { timeout: timeout + internal_1.ADDITIONAL_STEP_TIMEOUT } : undefined),
type: 5 /* LogEventType.InternalAction */,
});
};
exports.takeScreenshot = takeScreenshot;