feat: implement long press and double tap gestures
This commit is contained in:
@@ -54,4 +54,24 @@ test.describe('GestureSimulator - Swipe', () => {
|
|||||||
|
|
||||||
expect(transform).toBeTruthy();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -97,4 +97,28 @@ export class GestureSimulator {
|
|||||||
await this.page.touchscreen.touchEnd();
|
await this.page.touchscreen.touchEnd();
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user