feat: dispatch wheel event (#15593)

This commit is contained in:
Yury Semikhatsky 2022-07-12 17:17:45 -07:00 committed by GitHub
parent 00848b1bcf
commit 3436e64b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -853,6 +853,7 @@ export class InjectedScript {
case 'pointer': event = new PointerEvent(type, eventInit); break;
case 'focus': event = new FocusEvent(type, eventInit); break;
case 'drag': event = new DragEvent(type, eventInit); break;
case 'wheel': event = new WheelEvent(type, eventInit); break;
default: event = new Event(type, eventInit); break;
}
node.dispatchEvent(event);
@ -1155,7 +1156,7 @@ function oneLine(s: string): string {
return s.replace(/\n/g, '↵').replace(/\t/g, '⇆');
}
const eventType = new Map<string, 'mouse' | 'keyboard' | 'touch' | 'pointer' | 'focus' | 'drag'>([
const eventType = new Map<string, 'mouse' | 'keyboard' | 'touch' | 'pointer' | 'focus' | 'drag' | 'wheel'>([
['auxclick', 'mouse'],
['click', 'mouse'],
['dblclick', 'mouse'],
@ -1201,6 +1202,8 @@ const eventType = new Map<string, 'mouse' | 'keyboard' | 'touch' | 'pointer' | '
['dragleave', 'drag'],
['dragexit', 'drag'],
['drop', 'drag'],
['wheel', 'wheel'],
]);
const kHoverHitTargetInterceptorEvents = new Set(['mousemove']);

View File

@ -154,3 +154,20 @@ it('should dispatch click event via ElementHandles', async ({ page, server }) =>
await button.dispatchEvent('click');
expect(await page.evaluate(() => window['result'])).toBe('Clicked');
});
it('should dispatch wheel event', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15562' });
await page.goto(server.PREFIX + '/input/scrollable.html');
const eventsHandle = await page.locator('body').evaluateHandle(e => {
const events = [];
e.addEventListener('wheel', event => {
events.push(event);
console.log(event);
});
return events;
});
await page.locator('body').dispatchEvent('wheel', { deltaX: 100, deltaY: 200 });
expect(await eventsHandle.evaluate(e => e.length)).toBe(1);
expect(await eventsHandle.evaluate(e => e[0] instanceof WheelEvent)).toBeTruthy();
expect(await eventsHandle.evaluate(e => ({ deltaX: e[0].deltaX, deltaY: e[0].deltaY }))).toEqual({ deltaX: 100, deltaY: 200 });
});