diff --git a/cypress/integration/click.spec.ts b/cypress/integration/click.spec.ts index d539fb2..97233a1 100644 --- a/cypress/integration/click.spec.ts +++ b/cypress/integration/click.spec.ts @@ -50,6 +50,20 @@ describe("cy.realClick", () => { .realClick({ clickCount: 2 }); }); + it("should dispatch multiple clicks with clickCount greater than 1", (done) => { + let count = 0 + cy.get(".action-btn") + .then(($button) => { + $button.get(0).addEventListener("click", () => { + count++ + if (count === 2) { + done() + } + }); + }) + .realClick({ clickCount: 2 }); + }); + describe("scroll behavior", () => { function getScreenEdges() { const cypressAppWindow = window.parent.document.querySelector("iframe") diff --git a/src/commands/realClick.ts b/src/commands/realClick.ts index efcb26b..9d75218 100644 --- a/src/commands/realClick.ts +++ b/src/commands/realClick.ts @@ -65,25 +65,30 @@ export async function realClick( }); log.snapshot("before"); - await fireCdpCommand("Input.dispatchMouseEvent", { - type: "mousePressed", - x, - y, - clickCount: options.clickCount ?? 1, - buttons: 1, - pointerType: options.pointer ?? "mouse", - button: options.button ?? "left", - }); - await fireCdpCommand("Input.dispatchMouseEvent", { - type: "mouseReleased", - x, - y, - clickCount: options.clickCount ?? 1, - buttons: 1, - pointerType: options.pointer ?? "mouse", - button: options.button ?? "left", - }); + const { clickCount = 1 } = options + + for (let currentClick = 1; currentClick <= clickCount; currentClick++) { + await fireCdpCommand("Input.dispatchMouseEvent", { + type: "mousePressed", + x, + y, + clickCount: currentClick, + buttons: 1, + pointerType: options.pointer ?? "mouse", + button: options.button ?? "left", + }); + + await fireCdpCommand("Input.dispatchMouseEvent", { + type: "mouseReleased", + x, + y, + clickCount: currentClick, + buttons: 1, + pointerType: options.pointer ?? "mouse", + button: options.button ?? "left", + }); + } log.snapshot("after").end();