MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / dragElementBy

Function dragElementBy

core/src/utils/test/playwright/drag-element.ts:13–44  ·  view source on GitHub ↗
(
  el: Locator | ElementHandle<SVGElement | HTMLElement>,
  page: E2EPage,
  dragByX = 0,
  dragByY = 0,
  startXCoord?: number,
  startYCoord?: number,
  releaseDrag = true
)

Source from the content-addressed store, hash-verified

11import type { E2EPage } from './';
12
13export const dragElementBy = async (
14 el: Locator | ElementHandle<SVGElement | HTMLElement>,
15 page: E2EPage,
16 dragByX = 0,
17 dragByY = 0,
18 startXCoord?: number,
19 startYCoord?: number,
20 releaseDrag = true
21) => {
22 const boundingBox = await el.boundingBox();
23
24 if (!boundingBox) {
25 throw new Error(
26 'Cannot get a bounding box for an element that is not visible. See https://playwright.dev/docs/api/class-locator#locator-bounding-box for more information'
27 );
28 }
29
30 const startX = startXCoord === undefined ? boundingBox.x + boundingBox.width / 2 : startXCoord;
31 const startY = startYCoord === undefined ? boundingBox.y + boundingBox.height / 2 : startYCoord;
32
33 // Navigate to the start position.
34 await page.mouse.move(startX, startY);
35
36 await page.mouse.down();
37
38 // Drag the element.
39 await moveElement(page, startX, startY, dragByX, dragByY);
40
41 if (releaseDrag) {
42 await page.mouse.up();
43 }
44};
45
46/**
47 * Drags an element by the given amount of pixels on the Y axis.

Callers 15

menu.e2e.tsFile · 0.90
range.e2e.tsFile · 0.90
range.e2e.tsFile · 0.90

Calls 1

moveElementFunction · 0.85

Tested by

no test coverage detected