|
20 | 20 | <a/> |
21 | 21 | <p /> |
22 | 22 |
|
23 | | - |
24 | | -[](https://vshymanskyy.github.io/StandWithUkraine/) |
25 | | - |
26 | 23 | ## Why? |
27 | 24 |
|
28 | 25 | 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 simulated events, for example, to fill a native alert or copy to the clipboard. This plugin solves this problem. |
@@ -77,6 +74,13 @@ To include TypeScript declarations, add `"cypress-real-events"` to the `types` s |
77 | 74 | } |
78 | 75 | ``` |
79 | 76 |
|
| 77 | +## CI |
| 78 | + |
| 79 | +On CI in the same way as for regular cypress tests real commands will work only in the real browser. Make sure to install a real browser using `cypress install` command. |
| 80 | + |
| 81 | +> [!IMPORTANT] |
| 82 | +> cypress-browsers docker image has issues with running real events commands, the CDP protocol sometimes not working properly. It is recommended to use standard cypress/default or node:lts docker image and install browser using `cypress install` command. |
| 83 | +
|
80 | 84 | ## API |
81 | 85 |
|
82 | 86 | 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`. |
@@ -217,10 +221,10 @@ cy.realType(text, options); |
217 | 221 |
|
218 | 222 | #### Parameters: |
219 | 223 |
|
220 | | -| Name | Type | Default value | Description | |
221 | | -| --------- | ------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------- | |
222 | | -| `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. All the keys available [here](https://github.com/dmtrKovalenko/cypress-real-events/blob/main/src/keyCodeDefinitions.ts) | |
223 | | -| `options` | Options | {} | | |
| 224 | +| Name | Type | Default value | Description | |
| 225 | +| --------- | ------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 226 | +| `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. All the keys available [here](https://github.com/dmtrKovalenko/cypress-real-events/blob/main/src/keyCodeDefinitions.ts) | |
| 227 | +| `options` | Options | {} | | |
224 | 228 |
|
225 | 229 | Options: |
226 | 230 |
|
@@ -337,11 +341,11 @@ cy.get("div").realMouseWheel(options); |
337 | 341 | Example: |
338 | 342 |
|
339 | 343 | ```js |
340 | | -cy.get("div").realMouseWheel({ deltaY: 100 }) // Scroll down, mouse will be positioned at centered by default. |
341 | | -cy.get("div").realMouseWheel({ deltaY: -100 }) // Scroll up, mouse will be positioned at centered by default. |
342 | | -cy.get("div").realMouseWheel({ deltaX: 500 }) // Scroll right, mouse will be positioned at centered by default. |
343 | | -cy.get("div").realMouseWheel({ deltaX: -500 }) // Scroll left, mouse will be positioned at centered by default. |
344 | | -cy.get("div").realMouseWheel({ deltaY: 100, deltaX: 100 }) // Scroll right and down, mouse will be positioned at centered by default. |
| 344 | +cy.get("div").realMouseWheel({ deltaY: 100 }); // Scroll down, mouse will be positioned at centered by default. |
| 345 | +cy.get("div").realMouseWheel({ deltaY: -100 }); // Scroll up, mouse will be positioned at centered by default. |
| 346 | +cy.get("div").realMouseWheel({ deltaX: 500 }); // Scroll right, mouse will be positioned at centered by default. |
| 347 | +cy.get("div").realMouseWheel({ deltaX: -500 }); // Scroll left, mouse will be positioned at centered by default. |
| 348 | +cy.get("div").realMouseWheel({ deltaY: 100, deltaX: 100 }); // Scroll right and down, mouse will be positioned at centered by default. |
345 | 349 | ``` |
346 | 350 |
|
347 | 351 | Options: |
@@ -386,23 +390,25 @@ cy.get("body").realHover({ position: "topLeft" }); |
386 | 390 | cy.get("[aria-label='Test Button']").should( |
387 | 391 | "have.css", |
388 | 392 | "background-color", |
389 | | - "rgb(217, 83, 79)" |
| 393 | + "rgb(217, 83, 79)", |
390 | 394 | ); |
391 | 395 | ``` |
392 | 396 |
|
393 | 397 | ### 3. Why do I get "Are You Sure" popups when I am using real events and why I do not get them while using the normal cypress clicks? |
| 398 | + |
394 | 399 | Sometimes when there are unsaved changes in a webform, and you leave the page, the web application asks you due the `onbeforeunload event` if you really want to leaf the page and loose the changes. |
395 | 400 |
|
396 | 401 | You can try it on this [Demo Page](https://www.azyaamode.com/js/jquery/AYS/demo/are-you-sure-demo.html). |
397 | 402 |
|
398 | | -In "normal" Cypress tests, these popup windows do not appear. |
399 | | -This is because no "real" user actions are performed on the application. |
| 403 | +In "normal" Cypress tests, these popup windows do not appear. |
| 404 | +This is because no "real" user actions are performed on the application. |
400 | 405 | See [this](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#security) page for more information about the beforeunload event. |
401 | 406 | But when they appear, they block the whole test execution, and you have to handle them explicitly. |
402 | 407 | Gleb Bahmutov writes about this behaviour and possible solutions in this [Blog Post](https://glebbahmutov.com/blog/onbeforeunload/). |
403 | 408 |
|
404 | 409 | Now when you use this `real-events` plugin and perform a `realEvent` on your application, the browser thinks there happened a real user interaction. |
405 | 410 | From now on your test is in an `active interaction` state, which allows the application to use all the features listed [here](https://developer.mozilla.org/en-US/docs/Web/Security/User_activation). |
| 411 | + |
406 | 412 | ## UX |
407 | 413 |
|
408 | 414 | 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. |
|
0 commit comments