From a6b3f6ca737673fe4d34f48a6aeb80a70f4ded12 Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Thu, 2 Dec 2021 18:26:41 +0200 Subject: [PATCH 1/3] chore(docs): Fix twitter link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e474c7..3cd9f69 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ - +

From b05948e0ef938bfe342257e9104cf62d441a897c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 27 Dec 2021 19:12:25 +0100 Subject: [PATCH 2/3] feat(mouse button): Allow to specify button option for `realMouseDown` and `realMouseUp` (#201) --- README.md | 2 ++ cypress/integration/mouse.spec.ts | 26 ++++++++++++++++++++++++++ src/commands/mouseDown.ts | 10 ++++++++-- src/commands/mouseUp.ts | 9 +++++++-- src/mouseButtonNumbers.ts | 8 ++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/mouseButtonNumbers.ts diff --git a/README.md b/README.md index 06ef41d..f596006 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,7 @@ Options: - `Optional` **pointer**: \"mouse\" \| \"pen\" - `Optional` **position**: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight" - `Optional` **scrollBehavior**: "center" | "top" | "bottom" | "nearest" | false +- `Optional` **button**: "left" | "middle" | "right" | "back" | "forward" | "none" ## cy.realMouseUp @@ -296,6 +297,7 @@ Options: - `Optional` **pointer**: \"mouse\" \| \"pen\" - `Optional` **position**: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight" - `Optional` **scrollBehavior**: "center" | "top" | "bottom" | "nearest" | false +- `Optional` **button**: "left" | "middle" | "right" | "back" | "forward" | "none" ## Coordinates diff --git a/cypress/integration/mouse.spec.ts b/cypress/integration/mouse.spec.ts index d0c6382..629c925 100644 --- a/cypress/integration/mouse.spec.ts +++ b/cypress/integration/mouse.spec.ts @@ -36,6 +36,32 @@ describe("cy.realMouseDown and cy.realMouseUp", () => { .realMouseDown({ position: "bottomRight" }) .realMouseUp({ position: "bottomRight" }); }); + + describe("options.button", () => { + it("should allow to press down mouse using middle button", (done) => { + cy.get(".action-btn") + .then(($button) => { + $button.get(0).addEventListener("mousedown", (ev) => { + if (ev.button === 1) { + done(); + } + }); + }) + .realMouseDown({ button: "middle" }); + }); + + it("should allow to release mouse using middle button", (done) => { + cy.get(".action-btn") + .then(($button) => { + $button.get(0).addEventListener("mouseup", (ev) => { + if (ev.button === 1) { + done(); + } + }); + }) + .realMouseUp({ button: "middle" }); + }); + }); describe("realMouseDown scroll behavior", () => { function getScreenEdges() { diff --git a/src/commands/mouseDown.ts b/src/commands/mouseDown.ts index 04f0857..d7816b2 100644 --- a/src/commands/mouseDown.ts +++ b/src/commands/mouseDown.ts @@ -4,6 +4,7 @@ import { ScrollBehaviorOptions, Position, } from "../getCypressElementCoordinates"; +import { mouseButtonNumbers } from "../mouseButtonNumbers"; export interface realMouseDownOptions { /** Pointer type for realMouseDown, if "pen" touch simulated */ @@ -18,6 +19,11 @@ export interface realMouseDownOptions { * @example cy.realMouseDown({ scrollBehavior: "top" }); */ scrollBehavior?: ScrollBehaviorOptions; + + /** + * @default "left" + */ + button?: keyof typeof mouseButtonNumbers; } /** @ignore this, update documentation for this function at index.d.ts */ @@ -42,9 +48,9 @@ export async function realMouseDown( x, y, clickCount: 1, - buttons: 1, + buttons: mouseButtonNumbers[options.button ?? "left"], pointerType: options.pointer ?? "mouse", - button: "left", + button: options.button ?? "left", }); log.snapshot("after").end(); diff --git a/src/commands/mouseUp.ts b/src/commands/mouseUp.ts index c6794c5..783301e 100644 --- a/src/commands/mouseUp.ts +++ b/src/commands/mouseUp.ts @@ -4,6 +4,7 @@ import { ScrollBehaviorOptions, Position, } from "../getCypressElementCoordinates"; +import { mouseButtonNumbers } from "../mouseButtonNumbers"; export interface realMouseUpOptions { /** Pointer type for realMouseUp, if "pen" touch simulated */ @@ -18,6 +19,10 @@ export interface realMouseUpOptions { * @example cy.realMouseUp({ scrollBehavior: "top" }); */ scrollBehavior?: ScrollBehaviorOptions; + /** + * @default "left" + */ + button?: keyof typeof mouseButtonNumbers; } /** @ignore this, update documentation for this function at index.d.ts */ @@ -42,9 +47,9 @@ export async function realMouseUp( x, y, clickCount: 1, - buttons: 1, + buttons: mouseButtonNumbers[options.button ?? "left"], pointerType: options.pointer ?? "mouse", - button: "left", + button: options.button ?? "left", }); log.snapshot("after").end(); diff --git a/src/mouseButtonNumbers.ts b/src/mouseButtonNumbers.ts new file mode 100644 index 0000000..3d1c90f --- /dev/null +++ b/src/mouseButtonNumbers.ts @@ -0,0 +1,8 @@ +export const mouseButtonNumbers = { + "none": 0, + "left": 1, + "right": 2, + "middle": 4, + "back": 8, + "forward": 16, +} From 48a22b4be99cf73549f97a8da0a3c6d36fc2700a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 27 Dec 2021 11:45:08 +0100 Subject: [PATCH 3/3] chore(commands): laid out groundwork for state tracking --- cypress/integration/type.spec.ts | 4 +- src/_internalState.ts | 36 +++++++++ src/commands/realClick.ts | 46 ++++++----- src/commands/realHover.ts | 30 +++++-- .../{mouseDown.ts => realMouseDown.ts} | 40 ++++++++-- src/commands/{mouseUp.ts => realMouseUp.ts} | 39 ++++++++-- src/commands/realPress.ts | 78 ++++++------------- src/commands/realType.ts | 16 +--- src/getKeyCodeDefinitions.ts | 41 ++++++++++ src/index.d.ts | 4 +- src/keyCodeDefinitions.ts | 10 +-- src/mouseButtonNumbers.ts | 3 +- src/support.ts | 6 +- 13 files changed, 233 insertions(+), 120 deletions(-) create mode 100644 src/_internalState.ts rename src/commands/{mouseDown.ts => realMouseDown.ts} (74%) rename src/commands/{mouseUp.ts => realMouseUp.ts} (74%) create mode 100644 src/getKeyCodeDefinitions.ts diff --git a/cypress/integration/type.spec.ts b/cypress/integration/type.spec.ts index 7f91ad5..a7ed87e 100644 --- a/cypress/integration/type.spec.ts +++ b/cypress/integration/type.spec.ts @@ -4,9 +4,9 @@ describe("cy.realType", () => { cy.get("input[name=q]").focus() }); - it("types text into googles main search inptu", () => { + it("types text into an input", () => { cy.realType("cypress can produce real events"); - + cy.get("input[name=q]").should( "have.value", "cypress can produce real events" diff --git a/src/_internalState.ts b/src/_internalState.ts new file mode 100644 index 0000000..06befde --- /dev/null +++ b/src/_internalState.ts @@ -0,0 +1,36 @@ +import {mouseButtonNumbers} from './mouseButtonNumbers' + +const mouseButtons = new Set() + +function getButtonsMask(): number { + let mask = 0; + if (mouseButtons.has('left')) { + mask |= 1; + } + if (mouseButtons.has('right')) { + mask |= 2; + } + if (mouseButtons.has('middle')) { + mask |= 4; + } + if (mouseButtons.has('back')) { + mask |= 8; + } + if (mouseButtons.has('forward')) { + mask |= 16; + } + return mask; +} + +export const InternalState = { + clear() { + mouseButtons.clear() + }, + mouseButtonDown(button: keyof typeof mouseButtonNumbers) { + mouseButtons.add(button) + }, + mouseButtonUp(button: keyof typeof mouseButtonNumbers) { + mouseButtons.delete(button) + }, + getButtonsMask, +} diff --git a/src/commands/realClick.ts b/src/commands/realClick.ts index efcb26b..8b21237 100644 --- a/src/commands/realClick.ts +++ b/src/commands/realClick.ts @@ -1,15 +1,18 @@ -import { fireCdpCommand } from "../fireCdpCommand"; import { getCypressElementCoordinates, ScrollBehaviorOptions, Position, } from "../getCypressElementCoordinates"; +import { rawMouseDown } from './realMouseDown' +import { rawMouseUp } from './realMouseUp' +import { rawMouseMove } from './realHover' +import { mouseButtonNumbers } from "../mouseButtonNumbers"; export interface RealClickOptions { /** Pointer type for realClick, if "pen" touch simulated */ pointer?: "mouse" | "pen"; /** The button on mouse that clicked. Simulates real browser behavior. */ - button?: "none" | "left" | "right" | "middle" | "back" | "forward"; + button?: keyof typeof mouseButtonNumbers; /** * Position of the click event relative to the element * @example cy.realClick({ position: "topLeft" }) @@ -65,25 +68,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", + await rawMouseMove({ + ...options, x, - y, - clickCount: options.clickCount ?? 1, - buttons: 1, - pointerType: options.pointer ?? "mouse", - button: options.button ?? "left", - }); + y + }) + + const { clickCount = 1 } = options + + for (let currentClick = 1; currentClick <= clickCount; currentClick++) { + await rawMouseDown({ + ...options, + x, + y, + clickCount: currentClick + }) + + await rawMouseUp({ + ...options, + x, + y, + clickCount: currentClick + }) + } log.snapshot("after").end(); diff --git a/src/commands/realHover.ts b/src/commands/realHover.ts index 64e443e..4dbf9a9 100644 --- a/src/commands/realHover.ts +++ b/src/commands/realHover.ts @@ -4,13 +4,14 @@ import { ScrollBehaviorOptions, getCypressElementCoordinates, } from "../getCypressElementCoordinates"; +import { InternalState } from "../_internalState"; export interface RealHoverOptions { /** * If set to `pen`, simulates touch based hover (via long press) */ pointer?: "mouse" | "pen"; - /** + /** * Position relative to the element where to hover the element. * @example cy.realHover({ position: "topLeft" }) */ @@ -22,6 +23,25 @@ export interface RealHoverOptions { scrollBehavior?: ScrollBehaviorOptions; } +export async function rawMouseMove({ + x, + y, + pointer = "mouse", +}: { + x: number, + y: number, + pointer?: "mouse" | "pen", +}) { + await fireCdpCommand("Input.dispatchMouseEvent", { + type: "mouseMoved", + pointerType: pointer, + button: "none", + buttons: InternalState.getButtonsMask(), + x, + y, + }); +} + /** @ignore this, update documentation for this function at index.d.ts */ export async function realHover( subject: JQuery, @@ -38,13 +58,11 @@ export async function realHover( }), }); - await fireCdpCommand("Input.dispatchMouseEvent", { + await rawMouseMove({ + ...options, x, y, - type: "mouseMoved", - button: "none", - pointerType: options.pointer ?? "mouse", - }); + }) log.snapshot().end(); diff --git a/src/commands/mouseDown.ts b/src/commands/realMouseDown.ts similarity index 74% rename from src/commands/mouseDown.ts rename to src/commands/realMouseDown.ts index d7816b2..d624697 100644 --- a/src/commands/mouseDown.ts +++ b/src/commands/realMouseDown.ts @@ -5,6 +5,7 @@ import { Position, } from "../getCypressElementCoordinates"; import { mouseButtonNumbers } from "../mouseButtonNumbers"; +import { InternalState } from "../_internalState"; export interface realMouseDownOptions { /** Pointer type for realMouseDown, if "pen" touch simulated */ @@ -26,6 +27,32 @@ export interface realMouseDownOptions { button?: keyof typeof mouseButtonNumbers; } +export async function rawMouseDown({ + x, + y, + button = "left", + pointer = "mouse", + clickCount = 1, +}: { + x: number, + y: number, + button?: keyof typeof mouseButtonNumbers, + pointer?: "mouse" | "pen", + clickCount?: number +}) { + InternalState.mouseButtonUp(button) + + await fireCdpCommand("Input.dispatchMouseEvent", { + type: "mousePressed", + clickCount, + buttons: InternalState.getButtonsMask(), + pointerType: pointer, + button, + x, + y, + }); +} + /** @ignore this, update documentation for this function at index.d.ts */ export async function realMouseDown( subject: JQuery, @@ -43,15 +70,12 @@ export async function realMouseDown( }); log.snapshot("before"); - await fireCdpCommand("Input.dispatchMouseEvent", { - type: "mousePressed", + + await rawMouseDown({ + ...options, x, - y, - clickCount: 1, - buttons: mouseButtonNumbers[options.button ?? "left"], - pointerType: options.pointer ?? "mouse", - button: options.button ?? "left", - }); + y + }) log.snapshot("after").end(); diff --git a/src/commands/mouseUp.ts b/src/commands/realMouseUp.ts similarity index 74% rename from src/commands/mouseUp.ts rename to src/commands/realMouseUp.ts index 783301e..0e4a7c4 100644 --- a/src/commands/mouseUp.ts +++ b/src/commands/realMouseUp.ts @@ -5,6 +5,7 @@ import { Position, } from "../getCypressElementCoordinates"; import { mouseButtonNumbers } from "../mouseButtonNumbers"; +import { InternalState } from "../_internalState"; export interface realMouseUpOptions { /** Pointer type for realMouseUp, if "pen" touch simulated */ @@ -25,6 +26,31 @@ export interface realMouseUpOptions { button?: keyof typeof mouseButtonNumbers; } +export async function rawMouseUp({ + x, + y, + button = "left", + pointer = "mouse", + clickCount = 1, +}: { + x: number, + y: number, + button?: keyof typeof mouseButtonNumbers, + pointer?: "mouse" | "pen", + clickCount?: number +}) { + InternalState.mouseButtonUp(button) + await fireCdpCommand("Input.dispatchMouseEvent", { + type: "mouseReleased", + clickCount, + buttons: InternalState.getButtonsMask(), + pointerType: pointer, + button, + x, + y + }); +} + /** @ignore this, update documentation for this function at index.d.ts */ export async function realMouseUp( subject: JQuery, @@ -42,15 +68,12 @@ export async function realMouseUp( }); log.snapshot("before"); - await fireCdpCommand("Input.dispatchMouseEvent", { - type: "mouseReleased", + + await rawMouseUp({ + ...options, x, - y, - clickCount: 1, - buttons: mouseButtonNumbers[options.button ?? "left"], - pointerType: options.pointer ?? "mouse", - button: options.button ?? "left", - }); + y + }) log.snapshot("after").end(); diff --git a/src/commands/realPress.ts b/src/commands/realPress.ts index 64ee61e..890dbd5 100644 --- a/src/commands/realPress.ts +++ b/src/commands/realPress.ts @@ -1,5 +1,5 @@ import { fireCdpCommand } from "../fireCdpCommand"; -import { keyCodeDefinitions } from "../keyCodeDefinitions"; +import { getKeyCodeDefinitions, KeyDefinition, KeyOrShortcut } from "../getKeyCodeDefinitions"; export interface RealPressOptions { /** @@ -14,26 +14,6 @@ export interface RealPressOptions { log?: boolean; } -function getKeyDefinition(key: keyof typeof keyCodeDefinitions) { - const keyDefinition = keyCodeDefinitions[key]; - - if (!keyDefinition) { - throw new Error(`Unsupported key '${key}'.`); - } - - const keyCode = keyDefinition.keyCode ?? 0; - return { - keyCode: keyCode, - key: keyDefinition?.key ?? "", - text: keyDefinition.key.length === 1 ? keyDefinition.key : undefined, - // @ts-expect-error code exists anyway - code: keyDefinition.code ?? "", - // @ts-expect-error location exists anyway - location: keyDefinition.location ?? 0, - windowsVirtualKeyCode: keyCode, - }; -} - const keyToModifierBitMap: Record = { Alt: 1, Control: 2, @@ -41,31 +21,8 @@ const keyToModifierBitMap: Record = { Shift: 8, }; -type Key = keyof typeof keyCodeDefinitions; -// unfortunately passing a string like Shift+P is not possible cause typescript template literals can not handle such giant union -type KeyOrShortcut = Key | Array; - -/** @ignore this, update documentation for this function at index.d.ts */ -export async function realPress( - keyOrShortcut: KeyOrShortcut, - options: RealPressOptions = {} -) { - let log; - +export async function rawRealPress(keyDefinitions: KeyDefinition[], options: RealPressOptions = {}) { let modifiers = 0; - const keys = Array.isArray(keyOrShortcut) ? keyOrShortcut : [keyOrShortcut]; - const keyDefinitions = keys.map(getKeyDefinition); - - if (options.log ?? true) { - log = Cypress.log({ - name: "realPress", - consoleProps: () => ({ - "System Key Definition": keyDefinitions, - }), - }); - } - - log?.snapshot("before").end(); for (const key of keyDefinitions) { modifiers |= keyToModifierBitMap[key.key] ?? 0; @@ -76,14 +33,6 @@ export async function realPress( ...key, }); - if (key.code === "Enter") { - await fireCdpCommand("Input.dispatchKeyEvent", { - type: "char", - unmodifiedText: "\r", - text: "\r", - }); - } - await new Promise((res) => setTimeout(res, options.pressDelay ?? 25)); } @@ -96,6 +45,29 @@ export async function realPress( }); }) ); +} + +/** @ignore this, update documentation for this function at index.d.ts */ +export async function realPress( + keyOrShortcut: KeyOrShortcut, + options: RealPressOptions = {} +) { + let log; + + const keyDefinitions = getKeyCodeDefinitions(keyOrShortcut) + + if (options.log ?? true) { + log = Cypress.log({ + name: "realPress", + consoleProps: () => ({ + "System Key Definition": keyDefinitions, + }), + }); + } + + log?.snapshot("before").end(); + + await rawRealPress(keyDefinitions, options) log?.snapshot("after").end(); } diff --git a/src/commands/realType.ts b/src/commands/realType.ts index cfca9d3..602e8ab 100644 --- a/src/commands/realType.ts +++ b/src/commands/realType.ts @@ -1,5 +1,5 @@ -import { keyCodeDefinitions } from "../keyCodeDefinitions"; -import { realPress } from "./realPress"; +import { rawRealPress } from "./realPress"; +import { getKeyCodeDefinitions, Key } from "../getKeyCodeDefinitions"; export interface RealTypeOptions { /** @@ -19,15 +19,6 @@ export interface RealTypeOptions { log?: boolean; } -const availableChars = Object.keys(keyCodeDefinitions); -function assertChar( - char: string -): asserts char is keyof typeof keyCodeDefinitions { - if (!availableChars.includes(char)) { - throw new Error(`Unrecognized character "${char}".`); - } -} - /** @ignore this, update documentation for this function at index.d.ts */ export async function realType(text: string, options: RealTypeOptions = {}) { let log; @@ -52,8 +43,7 @@ export async function realType(text: string, options: RealTypeOptions = {}) { }, [] as string[]); for (const char of chars) { - assertChar(char); - await realPress(char, { + await rawRealPress(getKeyCodeDefinitions(char as Key), { pressDelay: options.pressDelay ?? 15, log: false, }); diff --git a/src/getKeyCodeDefinitions.ts b/src/getKeyCodeDefinitions.ts new file mode 100644 index 0000000..c81adaf --- /dev/null +++ b/src/getKeyCodeDefinitions.ts @@ -0,0 +1,41 @@ +import { keyCodeDefinitions } from "./keyCodeDefinitions"; + +export type Key = keyof typeof keyCodeDefinitions; +// unfortunately passing a string like Shift+P is not possible cause typescript template literals can not handle such giant union +export type KeyOrShortcut = Key | Array; +export type KeyDefinition = { + keyCode: number; + key: string; + text: string | undefined; + code: string; + location: number; + windowsVirtualKeyCode: number; +} + +function getKeyCodeDefinition(key: Key): KeyDefinition { + const keyDefinition = keyCodeDefinitions[key]; + + if (!keyDefinition) { + throw new Error(`Unsupported key '${key}'.`); + } + + const keyCode = keyDefinition.keyCode ?? 0; + return { + keyCode: keyCode, + key: keyDefinition?.key ?? "", + text: + "text" in keyDefinition + ? keyDefinition.text + : keyDefinition.key.length === 1 + ? keyDefinition.key + : undefined, + code: "code" in keyDefinition ? keyDefinition.code : "", + location: "location" in keyDefinition ? keyDefinition.location : 0, + windowsVirtualKeyCode: keyCode, + }; +} + +export function getKeyCodeDefinitions(keyOrShortcut: KeyOrShortcut) { + const keys = Array.isArray(keyOrShortcut) ? keyOrShortcut : [keyOrShortcut]; + return keys.map(getKeyCodeDefinition); +} diff --git a/src/index.d.ts b/src/index.d.ts index 4be0d1c..5414e92 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -82,7 +82,7 @@ declare namespace Cypress { * cy.get("button").realMouseDown() */ realMouseDown: NormalizeCypressCommand< - typeof import("./commands/mouseDown").realMouseDown + typeof import("./commands/realMouseDown").realMouseDown >; /** * Fires native system mouseReleased event. @@ -91,7 +91,7 @@ declare namespace Cypress { * cy.get("button").realMouseUp() */ realMouseUp: NormalizeCypressCommand< - typeof import("./commands/mouseUp").realMouseUp + typeof import("./commands/realMouseUp").realMouseUp >; } } diff --git a/src/keyCodeDefinitions.ts b/src/keyCodeDefinitions.ts index fcadbb0..af6b59f 100644 --- a/src/keyCodeDefinitions.ts +++ b/src/keyCodeDefinitions.ts @@ -19,11 +19,11 @@ export const keyCodeDefinitions = { '{backspace}': {'keyCode': 8, 'code': 'Backspace', 'key': 'Backspace'}, 'Tab': {'keyCode': 9, 'code': 'Tab', 'key': 'Tab'}, 'Numpad5': {'keyCode': 12, 'shiftKeyCode': 101, 'key': 'Clear', 'code': 'Numpad5', 'shiftKey': '5', 'location': 3}, - 'NumpadEnter': {'keyCode': 13, 'code': 'NumpadEnter', 'key': 'Enter', 'location': 3}, - '{enter}': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter'}, - 'Enter': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter'}, - '\r': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter'}, - '\n': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter'}, + 'NumpadEnter': {'keyCode': 13, 'code': 'NumpadEnter', 'key': 'Enter', 'text': '\r', 'location': 3}, + '{enter}': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, + 'Enter': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, + '\r': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, + '\n': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}, 'ShiftLeft': {'keyCode': 16, 'code': 'ShiftLeft', 'key': 'Shift', 'location': 1}, 'ShiftRight': {'keyCode': 16, 'code': 'ShiftRight', 'key': 'Shift', 'location': 2}, 'ControlLeft': {'keyCode': 17, 'code': 'ControlLeft', 'key': 'Control', 'location': 1}, diff --git a/src/mouseButtonNumbers.ts b/src/mouseButtonNumbers.ts index 3d1c90f..4d9803c 100644 --- a/src/mouseButtonNumbers.ts +++ b/src/mouseButtonNumbers.ts @@ -1,8 +1,7 @@ export const mouseButtonNumbers = { - "none": 0, "left": 1, "right": 2, "middle": 4, "back": 8, "forward": 16, -} +} as const diff --git a/src/support.ts b/src/support.ts index d8a9df4..69206f1 100644 --- a/src/support.ts +++ b/src/support.ts @@ -4,9 +4,11 @@ import { realSwipe } from "./commands/realSwipe"; import { realPress } from "./commands/realPress"; import { realType } from "./commands/realType"; import { realTouch } from "./commands/realTouch"; -import { realMouseDown } from "./commands/mouseDown"; -import { realMouseUp } from "./commands/mouseUp"; +import { realMouseDown } from "./commands/realMouseDown"; +import { realMouseUp } from "./commands/realMouseUp"; +import { InternalState } from './_internalState' +Cypress.on('window:before:load', InternalState.clear) // TODO fix this unsafe convertions. This happens because cypress does not allow anymore to return Promise for types, but allows for command which is pretty useful for current implementation. Cypress.Commands.add(