feat: implement pinch gesture in GestureSimulator
This commit is contained in:
@@ -69,4 +69,32 @@ export class GestureSimulator {
|
||||
duration: 800,
|
||||
});
|
||||
}
|
||||
|
||||
async pinch(options: PinchOptions): Promise<void> {
|
||||
const { centerX, centerY, startDistance, endDistance, duration } = options;
|
||||
|
||||
const startDistanceX = startDistance / 2;
|
||||
const startDistanceY = startDistance / 2;
|
||||
const endDistanceX = endDistance / 2;
|
||||
const endDistanceY = endDistance / 2;
|
||||
|
||||
const steps = 10;
|
||||
const stepDuration = duration / steps;
|
||||
|
||||
await this.page.touchscreen.tap(centerX - startDistanceX, centerY - startDistanceY);
|
||||
await this.page.touchscreen.tap(centerX + startDistanceX, centerY + startDistanceY);
|
||||
|
||||
for (let i = 1; i <= steps; i++) {
|
||||
const progress = i / steps;
|
||||
const currentDistanceX = startDistanceX + (endDistanceX - startDistanceX) * progress;
|
||||
const currentDistanceY = startDistanceY + (endDistanceY - startDistanceY) * progress;
|
||||
|
||||
await this.page.touchscreen.touchMove(centerX - currentDistanceX, centerY - currentDistanceY);
|
||||
await this.page.touchscreen.touchMove(centerX + currentDistanceX, centerY + currentDistanceY);
|
||||
await this.page.waitForTimeout(stepDuration);
|
||||
}
|
||||
|
||||
await this.page.touchscreen.touchEnd();
|
||||
await this.page.touchscreen.touchEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user