All Projects โ†’ dmtrKovalenko โ†’ Cypress Real Events

dmtrKovalenko / Cypress Real Events

Licence: mit
Fire native system events from Cypress.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Cypress Real Events

corde
๐Ÿค– A simple e2e library for testing Discord Bots ๐Ÿš€
Stars: โœญ 60 (-63.41%)
Mutual labels:  e2e
Protractor Best Practices
Stars: โœญ 65 (-60.37%)
Mutual labels:  e2e
Dappeteer
๐ŸŒ๐Ÿผโ€E2E testing for dApps using Puppeteer + MetaMask
Stars: โœญ 117 (-28.66%)
Mutual labels:  e2e
Syncano Dashboard
The Syncano Dashboard built with React.
Stars: โœญ 287 (+75%)
Mutual labels:  e2e
Metac
It is metacontroller and more
Stars: โœญ 50 (-69.51%)
Mutual labels:  e2e
Conceal Core
Conceal Core - Daemon & Wallets (CLI)
Stars: โœญ 72 (-56.1%)
Mutual labels:  e2e
dappeteer
๐ŸŒ๐Ÿผโ€E2E testing for dApps using Puppeteer + MetaMask
Stars: โœญ 138 (-15.85%)
Mutual labels:  e2e
Kakunin
An E2E testing framework
Stars: โœญ 141 (-14.02%)
Mutual labels:  e2e
Tib
Easy e2e browser testing in Node
Stars: โœญ 64 (-60.98%)
Mutual labels:  e2e
Sakuli
Sakuli is an end-2-end testing and monitoring tool for web sites and common UIs with multiple monitoring integrations
Stars: โœญ 115 (-29.88%)
Mutual labels:  e2e
Jianshu
ไปฟ็ฎ€ไนฆnx+nodejs+nestjs6+express+mongodb+angular8+็ˆฌ่™ซ
Stars: โœญ 296 (+80.49%)
Mutual labels:  e2e
E2e Tester
Open source End-to-End test service
Stars: โœญ 6 (-96.34%)
Mutual labels:  e2e
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: โœญ 9,176 (+5495.12%)
Mutual labels:  e2e
angular-webpack-skeleton
This project is deprecated. Please refer to https://github.com/Ks89/angular-cli-skeleton
Stars: โœญ 16 (-90.24%)
Mutual labels:  e2e
Cypress React Selector
โšก๏ธ cypress plugin to locate react elements by component, props and state
Stars: โœญ 121 (-26.22%)
Mutual labels:  e2e
babel-plugin-remove-test-ids
๐Ÿ  Babel plugin to strip `data-test-id` HTML attributes
Stars: โœญ 40 (-75.61%)
Mutual labels:  e2e
Nativescript Dev Appium
A package to help with writing and executing e2e Appium tests in NativeScript apps
Stars: โœญ 69 (-57.93%)
Mutual labels:  e2e
Playwright Video
๐ŸŽฌ Save a video of a Playwright page
Stars: โœญ 162 (-1.22%)
Mutual labels:  e2e
Javascript Testing Best Practices
๐Ÿ“—๐ŸŒ ๐Ÿšข Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: โœญ 13,976 (+8421.95%)
Mutual labels:  e2e
Cypress Svelte Unit Test
Unit testing Svelte components in Cypress E2E test runner
Stars: โœญ 110 (-32.93%)
Mutual labels:  e2e

Cypress Real Events

Fire native system events from Cypress

npm version npm version

Why?

Cypress default events are simulated. That means that all events like cy.click or cy.type are fired from javascript. That's why these events will be untrusted (event.isTrusted will be false) and they can behave a little different from real native events. But for some cases it can be impossible to use native events, for example to fill a native alert or copy to the clipboard.

Thanks to Chrome Devtools Protocol. Cypress is connecting to CDP for tasks like screenshots, this project is using the same connection to fire system events. It works literally like in puppeteer. And as a result unlocks such features like hovering and native focus management via Tab.

Requirements

Cypress only. Really. Cypress itself can fire native events. The only limitation for real events โ€“ they work only in the chromium-based browser. That means that Firefox is not supported, at least for now.

Quick overview

Here is a simple test that can be written with native events:

it("tests real events", () => {
  cy.get("input").realClick(); // perform a native real click on the field
  cy.realType("cypress real event"); // fires native system keypress events and fills the field
  cy.realPress("Tab"); // native tab click switches the focus
  cy.focused().realHover(); // hovers over the new focused element
  cy.contains("some text in the hovered popover");
});

Installation

Install npm package:

npm install cypress-real-events

yarn add cypress-real-events

Register new commands by adding this to your cypress/support/index.{js,ts} file.

import "cypress-real-events/support";

If you are using typescript, also add the following to cypress/tsconfig.json

{
  "compilerOptions": {
    "types": ["cypress", "cypress-real-events"]
  }
}

API

The idea of the commands โ€“ they should be as similar as possible to cypress default commands (like cy.type), but starts with real โ€“ cy.realType.

Here is an overview of the available real event commands:

cy.realClick

Fires native system click event.

cy.get("button").realClick();
cy.get("button").realClick(options);

Example:

cy.get("button").realClick({ position: "topLeft" }) // click on the top left corner of button
cy.get("body").realClick({ x: 100, y: 1240 }) // click by the x & y coordinates relative to the whole window

Options:

  • Optional button: "none" | "left" | "right" | "middle" | "back" | "forward"
  • Optional pointer: "mouse" | "pen"
  • Optional x coordinate to click x: number
  • Optional y coordinate to click y: number
  • Optional position: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"

Make sure that x and y has a bigger priority than position.

cy.realHover

Fires a real native hover event. Yes, it can test :hover preprocessor.

cy.get("button").realHover();
cy.get("button").realHover(options);

Options:

  • Optional pointer: "mouse" | "pen"
  • Optional position: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"

cy.realPress

Fires native press event. It can fire one key event or the "shortcut" like Shift+Control+M. Make sure that event is global, it means that it is required to firstly focus any control before firing this event.

cy.realPress("Tab"); // switch the focus for a11y testing
cy.realPress(["Alt", "Meta", "P"]) // Alt+(Command or Control)+P

Usage

cy.realPress(key);
cy.realPress(key, options);

Parameters:

Name Type Default value Description
key string string[] -
options - Optional pointer: "mouse" | "pen" {}

cy.realTouch

Fires native system touch event.

cy.get("button").realTouch();
cy.get("button").realTouch(options);
Usage:
cy.get("button").realTouch({ position: "topLeft" }) // touches the top left corner of button
cy.get("body").realTouch({ x: 100, y: 1240 }) // touches the x & y coordinates relative to the whole window

Options:

  • Optional x: undefined | number default 30
  • Optional y: undefined | false | true default true
  • Optional position: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"
  • Optional radius: undefined | number default 1
  • Optional radiusX: undefined | number default 1
  • Optional radiusY: undefined | number default 1

cy.realType

Runs a sequence of native press events (via cy.realPress). This can be used to simulate real typing. Make sure that type event is global. This means that it is not attached to any field.

cy.realType("type any text"); // type any text on the page

cy.get("input").focus();
cy.realType("some text {enter}"); // type into focused field

Usage:

cy.realType(text);
cy.realType(text, options);

Parameters:

Name Type Default value Description
text string - text to type. Should be around the same as cypress's type command argument (https://docs.cypress.io/api/commands/type.html#Arguments)
options Options {}

Options:

  • Optional delay: undefined | number default 30
  • Optional log: undefined | false | true default true
  • Optional pressDelay: undefined | number default 10

cy.realSwipe

Runs a native swipe events. It means that touch events will be fired. Actually a sequence of touchStart -> touchMove -> touchEnd. It can perfectly swipe drawers and other tools like this one.

Make sure to enable mobile viewport :)

cy.get('.element').realSwipe("toLeft");  // swipes from right to left
cy.get('.element').realSwipe("toRight"); // inverted

Usage:

cy.realSwipe(direction);
cy.realSwipe(direction, options);

Parameters:

Name Type Default value Description
direction `"toLeft" "toTop" "toRight"
options Options {}

Options:

  • Optional length: undefined | number default 10
  • Optional x coordinate to touch x: number
  • Optional y coordinate to touch y: number
  • Optional touchPosition: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"

UX

One problem of the real native system events I need to mention โ€“ you will not get an error message if the event wasn't produced. Similar to selenium or playwright โ€“ if a javascript event was not fired you will not get a comprehensive error message.

So probably this package should not be used as a replacement of the cypress events, at least for the writing tests experience ๐Ÿจ

License

The project is licensed under the terms of MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].