Test tap, double-tap, long-press
Touch gestures are the foundation of mobile interaction. Testing requires device emulation or real device access. Playwright supports touch via touchscreen API.
Interact with touch gestures
๐
Touch Here
Try tap, double-tap, and long-press
๐ก On desktop, use Chrome DevTools device mode (F12 โ Toggle device toolbar)
Complete all gestures
Tap
Single quick touch
Double Tap
Two quick taps
Long Press
Touch and hold 500ms+
Gesture detection history
No gestures detected yet. Touch the area above.
Automation hints
// Enable touch for mobile emulation
const context = await browser.newContext({
...devices['iPhone 14'],
hasTouch: true
});
// Tap
await page.tap('[data-testid="touch-area"]');
// Double tap
await page.tap('[data-testid="touch-area"]');
await page.tap('[data-testid="touch-area"]');
// Long press using touchscreen
await page.touchscreen.tap(200, 200);
await page.waitForTimeout(600);
// Or with mouse (for testing)
await page.locator('[data-testid="touch-area"]')
.click({ delay: 600 });// Single tap
driver.findElement(By.id("touch-area")).click();
// Double tap
TouchAction action = new TouchAction(driver);
action.doubleTap(element).perform();
// Long press
action.longPress(element)
.waitAction(Duration.ofMillis(600))
.release()
.perform();
// With coordinates
action.tap(PointOption.point(200, 300))
.perform();