feat: implement long press and double tap gestures

This commit is contained in:
张翔
2026-03-05 14:59:06 +08:00
parent 302fafef49
commit 12ff5fc1f3
2 changed files with 44 additions and 0 deletions
@@ -54,4 +54,24 @@ test.describe('GestureSimulator - Swipe', () => {
expect(transform).toBeTruthy();
});
test('should perform long press', async ({ page }) => {
await page.goto('/');
const simulator = new GestureSimulator(page);
const card = page.locator('.card').first();
await simulator.longPress(card, 1000);
await expect(card).toBeVisible();
});
test('should perform double tap', async ({ page }) => {
await page.goto('/products');
const simulator = new GestureSimulator(page);
const image = page.locator('.product-image').first();
await simulator.doubleTap(image);
await expect(image).toBeVisible();
});
});
+24
View File
@@ -97,4 +97,28 @@ export class GestureSimulator {
await this.page.touchscreen.touchEnd();
await this.page.touchscreen.touchEnd();
}
async longPress(element: Locator, duration: number = 1000): Promise<void> {
const box = await element.boundingBox();
if (!box) throw new Error('Element not visible');
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await this.page.touchscreen.tap(x, y);
await this.page.waitForTimeout(duration);
await this.page.touchscreen.touchEnd();
}
async doubleTap(element: Locator): Promise<void> {
const box = await element.boundingBox();
if (!box) throw new Error('Element not visible');
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await this.page.touchscreen.tap(x, y);
await this.page.waitForTimeout(100);
await this.page.touchscreen.tap(x, y);
}
}