mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(playwright): dragElementByYAxis util (#25346)
This commit is contained in:
@@ -29,7 +29,42 @@ export const dragElementBy = async (
|
||||
|
||||
await page.mouse.move(startX, startY);
|
||||
await page.mouse.down();
|
||||
|
||||
await page.mouse.move(midX, midY);
|
||||
await page.mouse.move(endX, endY);
|
||||
await page.mouse.up();
|
||||
};
|
||||
|
||||
/**
|
||||
* Drags an element by the given amount of pixels on the Y axis.
|
||||
* @param el The element to drag.
|
||||
* @param page The E2E Page object.
|
||||
* @param dragByY The amount of pixels to drag the element by.
|
||||
* @param startYCoord The Y coordinate to start the drag gesture at. Defaults to the center of the element.
|
||||
*/
|
||||
export const dragElementByYAxis = async (
|
||||
el: Locator | ElementHandle<SVGElement | HTMLElement>,
|
||||
page: E2EPage,
|
||||
dragByY: number,
|
||||
startYCoord?: number
|
||||
) => {
|
||||
const boundingBox = await el.boundingBox();
|
||||
|
||||
if (!boundingBox) {
|
||||
throw new Error(
|
||||
'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'
|
||||
);
|
||||
}
|
||||
|
||||
const startX = boundingBox.x + boundingBox.width / 2;
|
||||
const startY = startYCoord === undefined ? boundingBox.y + boundingBox.height / 2 : startYCoord;
|
||||
|
||||
await page.mouse.move(startX, startY);
|
||||
await page.mouse.down();
|
||||
|
||||
for (let i = 0; i < dragByY; i += 20) {
|
||||
await page.mouse.move(startX, startY + i);
|
||||
}
|
||||
|
||||
await page.mouse.up();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user