UNPKG

e2ed

Version:

E2E testing framework over Playwright

44 lines (43 loc) 1.73 kB
"use strict"; /* eslint-disable no-param-reassign */ Object.defineProperty(exports, "__esModule", { value: true }); exports.scroll = void 0; const log_1 = require("../utils/log"); const selectors_1 = require("../utils/selectors"); /** * Scrolls the document (or element) to the specified absolute position. */ exports.scroll = ((...args) => { const printedArgs = [...args]; if (args[0] instanceof selectors_1.Selector) { printedArgs.shift(); } const selector = args[0] instanceof selectors_1.Selector ? args[0] : selectors_1.Selector.create({ cssString: 'html', parameterAttributePrefix: 'data-test-', testIdAttribute: 'data-testid', testIdSeparator: '-', }); (0, log_1.log)('Scroll the document (or element) to the specified position', { args: printedArgs, selector }, 5 /* LogEventType.InternalAction */); return selector.getPlaywrightLocator().evaluate((el, clientArgs) => { const centerX = Math.floor(el.scrollWidth / 2 - el.clientWidth / 2); const centerY = Math.floor(el.scrollHeight / 2 - el.clientHeight / 2); const positions = { bottom: [centerX, el.scrollHeight], bottomLeft: [0, el.scrollHeight], bottomRight: [el.scrollWidth, el.scrollHeight], center: [centerX, centerY], left: [0, centerY], right: [el.scrollWidth, centerY], top: [centerX, 0], topLeft: [0, 0], topRight: [el.scrollWidth, 0], }; const position = positions[clientArgs[0]]; const [x, y] = position ?? clientArgs; el.scrollLeft = x; el.scrollTop = y; }, printedArgs); });