|
1 |
| -import { fireCdpCommand } from "../fireCdpCommand"; |
2 | 1 | import {
|
3 | 2 | getCypressElementCoordinates,
|
4 | 3 | ScrollBehaviorOptions,
|
5 | 4 | Position,
|
6 | 5 | } from "../getCypressElementCoordinates";
|
| 6 | +import { rawMouseDown } from './realMouseDown' |
| 7 | +import { rawMouseUp } from './realMouseUp' |
| 8 | +import { rawMouseMove } from './realHover' |
| 9 | +import { mouseButtonNumbers } from "../mouseButtonNumbers"; |
7 | 10 |
|
8 | 11 | export interface RealClickOptions {
|
9 | 12 | /** Pointer type for realClick, if "pen" touch simulated */
|
10 | 13 | pointer?: "mouse" | "pen";
|
11 | 14 | /** The button on mouse that clicked. Simulates real browser behavior. */
|
12 |
| - button?: "none" | "left" | "right" | "middle" | "back" | "forward"; |
| 15 | + button?: keyof typeof mouseButtonNumbers; |
13 | 16 | /**
|
14 | 17 | * Position of the click event relative to the element
|
15 | 18 | * @example cy.realClick({ position: "topLeft" })
|
@@ -65,25 +68,30 @@ export async function realClick(
|
65 | 68 | });
|
66 | 69 |
|
67 | 70 | log.snapshot("before");
|
68 |
| - await fireCdpCommand("Input.dispatchMouseEvent", { |
69 |
| - type: "mousePressed", |
70 |
| - x, |
71 |
| - y, |
72 |
| - clickCount: options.clickCount ?? 1, |
73 |
| - buttons: 1, |
74 |
| - pointerType: options.pointer ?? "mouse", |
75 |
| - button: options.button ?? "left", |
76 |
| - }); |
77 | 71 |
|
78 |
| - await fireCdpCommand("Input.dispatchMouseEvent", { |
79 |
| - type: "mouseReleased", |
| 72 | + await rawMouseMove({ |
| 73 | + ...options, |
80 | 74 | x,
|
81 |
| - y, |
82 |
| - clickCount: options.clickCount ?? 1, |
83 |
| - buttons: 1, |
84 |
| - pointerType: options.pointer ?? "mouse", |
85 |
| - button: options.button ?? "left", |
86 |
| - }); |
| 75 | + y |
| 76 | + }) |
| 77 | + |
| 78 | + const { clickCount = 1 } = options |
| 79 | + |
| 80 | + for (let currentClick = 1; currentClick <= clickCount; currentClick++) { |
| 81 | + await rawMouseDown({ |
| 82 | + ...options, |
| 83 | + x, |
| 84 | + y, |
| 85 | + clickCount: currentClick |
| 86 | + }) |
| 87 | + |
| 88 | + await rawMouseUp({ |
| 89 | + ...options, |
| 90 | + x, |
| 91 | + y, |
| 92 | + clickCount: currentClick |
| 93 | + }) |
| 94 | + } |
87 | 95 |
|
88 | 96 | log.snapshot("after").end();
|
89 | 97 |
|
|
0 commit comments