mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-08 23:58:13 +08:00
chore(playwright): dragElementByYAxis util (#25346)
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import type { E2EPage } from '@utils/test/playwright';
|
||||
import { dragElementByYAxis } from '@utils/test/playwright';
|
||||
|
||||
/**
|
||||
* Emulates a pull-to-refresh drag gesture (pulls down and releases).
|
||||
@ -16,23 +17,8 @@ const pullToRefresh = async (page: E2EPage, selector = 'body') => {
|
||||
await page.waitForSelector('ion-refresher.hydrated', { state: 'attached' });
|
||||
|
||||
const ev = await page.spyOnEvent('ionRefreshComplete');
|
||||
const boundingBox = await target.boundingBox();
|
||||
|
||||
if (!boundingBox) {
|
||||
return;
|
||||
}
|
||||
|
||||
const startX = boundingBox.x + boundingBox.width / 2;
|
||||
const startY = boundingBox.y + boundingBox.height / 2;
|
||||
|
||||
await page.mouse.move(startX, startY);
|
||||
await page.mouse.down();
|
||||
|
||||
for (let i = 0; i < 400; i += 20) {
|
||||
await page.mouse.move(startX, startY + i);
|
||||
}
|
||||
|
||||
await page.mouse.up();
|
||||
await dragElementByYAxis(target, page, 400);
|
||||
await ev.next();
|
||||
};
|
||||
|
||||
|
||||
@ -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