Gesture tests send a drag's touches at once, not one by one (#184)

Each touch event was awaited before the next went, so on a busy machine a
drag's ten messages took longer than the 800 ms a swipe has, and the page
took it for a slow drag. Reproduced by spacing the messages 110 ms apart:
the swipe back stayed on Second Episode, as the failing run did. The page
is right to want a swipe quick; a finger does it in well under that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 12:58:26 +00:00
parent c214b3e79a
commit ba9759f44f

View File

@@ -1429,15 +1429,17 @@ test('a failing feed is marked on its artwork and says why', async ({ page }) =>
test.describe('touch gestures on a phone', () => { test.describe('touch gestures on a phone', () => {
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true }); test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
// Playwright's touchscreen only taps; a drag goes through the DevTools protocol. // Playwright's touchscreen only taps; a drag goes through the DevTools protocol. Sent all at
// once, in order: awaited one by one, a busy machine stretched a drag past the 800 ms a swipe
// has, and it was taken for a slow drag and went nowhere (#184).
async function drag(page, from, to, lift = true) { async function drag(page, from, to, lift = true) {
const cdp = await page.context().newCDPSession(page); const cdp = await page.context().newCDPSession(page);
const steps = 8; const steps = 8, touch = (type, touchPoints) => cdp.send('Input.dispatchTouchEvent', { type, touchPoints });
await cdp.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [from] }); const sent = [touch('touchStart', [from])];
for (let i = 1; i <= steps; i++) for (let i = 1; i <= steps; i++)
await cdp.send('Input.dispatchTouchEvent', { type: 'touchMove', touchPoints: [{ sent.push(touch('touchMove', [{ x: from.x + (to.x - from.x) * i / steps, y: from.y + (to.y - from.y) * i / steps }]));
x: from.x + (to.x - from.x) * i / steps, y: from.y + (to.y - from.y) * i / steps }] }); if (lift) sent.push(touch('touchEnd', []));
if (lift) await cdp.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }); await Promise.all(sent);
return cdp; return cdp;
} }