UNPKG

@visual-regression-tracker/agent-playwright

Version:

Native integration for Playwright with Visual Regression Tracker

69 lines (68 loc) 3.92 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightVisualRegressionTracker = void 0; const sdk_js_1 = require("@visual-regression-tracker/sdk-js"); class PlaywrightVisualRegressionTracker { constructor(browserName, config) { this.vrt = new sdk_js_1.VisualRegressionTracker(config); this.browser = browserName; } start() { return __awaiter(this, void 0, void 0, function* () { return this.vrt.start(); }); } stop() { return __awaiter(this, void 0, void 0, function* () { return this.vrt.stop(); }); } trackPage(page, name, options, retryCount = 2) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const viewportSize = page.viewportSize(); return this.vrt.track({ name, imageBase64: (yield page.screenshot(options === null || options === void 0 ? void 0 : options.screenshotOptions)).toString("base64"), browser: this.browser, viewport: viewportSize ? `${viewportSize.width}x${viewportSize.height}` : undefined, os: (_a = options === null || options === void 0 ? void 0 : options.agent) === null || _a === void 0 ? void 0 : _a.os, device: (_b = options === null || options === void 0 ? void 0 : options.agent) === null || _b === void 0 ? void 0 : _b.device, diffTollerancePercent: options === null || options === void 0 ? void 0 : options.diffTollerancePercent, ignoreAreas: options === null || options === void 0 ? void 0 : options.ignoreAreas, comment: options === null || options === void 0 ? void 0 : options.comment, }, retryCount); }); } trackElementHandle(elementHandle, name, options, retryCount = 2) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { if (!elementHandle) { throw new Error("ElementHandle is null"); } return this.vrt.track({ name, imageBase64: (yield elementHandle.screenshot(options === null || options === void 0 ? void 0 : options.screenshotOptions)).toString("base64"), browser: this.browser, viewport: (_a = options === null || options === void 0 ? void 0 : options.agent) === null || _a === void 0 ? void 0 : _a.viewport, os: (_b = options === null || options === void 0 ? void 0 : options.agent) === null || _b === void 0 ? void 0 : _b.os, device: (_c = options === null || options === void 0 ? void 0 : options.agent) === null || _c === void 0 ? void 0 : _c.device, diffTollerancePercent: options === null || options === void 0 ? void 0 : options.diffTollerancePercent, ignoreAreas: options === null || options === void 0 ? void 0 : options.ignoreAreas, comment: options === null || options === void 0 ? void 0 : options.comment, }, retryCount); }); } } exports.PlaywrightVisualRegressionTracker = PlaywrightVisualRegressionTracker;