UNPKG

@uuv/cypress

Version:

A solution to facilitate the writing and execution of E2E tests understandable by any human being using cucumber(BDD) and cypress

194 lines (166 loc) 7.55 kB
/******************************* NE PAS MODIFIER, FICHIER GENERE *******************************/ /** * Software Name : UUV * * SPDX-License-Identifier: MIT * * This software is distributed under the MIT License, * see the "LICENSE" file for more details * * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley * Software description: Make test writing fast, understandable by any human * understanding English or French. */ import { Then, When, } from "@badeball/cypress-cucumber-preprocessor"; import "../../../../../../cypress/commands"; import { click, findWithRoleAndName, findWithRoleAndNameAndAttribute, findWithRoleAndNameAndContent, findWithRoleAndNameAndContentDisabled, findWithRoleAndNameAndContentEnabled, findWithRoleAndNameDisabled, findWithRoleAndNameEnabled, findWithRoleAndNameFocused, notFoundWithRoleAndName, withinRoleAndName } from "../../../core-engine"; import { pressKey } from "../../../_.common"; // Begin of General Section /** * Sélectionne l'élément ayant le rôle button et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) sont spécifiés <br />⚠ pensez à déselectionner l'élement avec <b>[je reinitialise le contexte](#je-reinitialise-le-contexte)</b> si vous n'agissez plus dessus * */ When(`je vais à l'intérieur du bouton nommé {string}`, function(name: string) { withinRoleAndName("button", name); }); /** * Vérifie l'existence d'un élément Html ayant le rôle button et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés * */ Then(`je dois voir un bouton nommé {string}`, function(name: string) { findWithRoleAndName("button", name); }); /** * Vérifie l'inexistence d'un élément Html ayant le rôle button et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés * */ Then( `je ne dois pas voir un bouton nommé {string}`, function(name: string) { notFoundWithRoleAndName("button", name); } ); // End of General Section // Begin of Click Section /** * Déclenche un click sur l'élément Html ayant le rôle $roleId, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) * */ When(`je clique sur le bouton nommé {string}`, function(name: string) { click("button", name); }); // End of Click Section // Begin of Type Section /** * Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire). * */ When(`je saisie le(s) mot(s) {string} dans le bouton nommé {string}`, function(textToType: string, name: string) { cy.uuvFindByRole("button", { name: name }).uuvFoundedElement().type(textToType); }); /** * Saisie de la phrase passée en paramètre dans le champ spécifié (utile par exemple pour remplir un champ de formulaire). * */ When(`j'entre la valeur {string} dans le bouton nommé {string}`, function(textToType: string, name: string) { cy.uuvFindByRole("button", { name: name }).uuvFoundedElement().type(textToType); }); /** * Vérifie l'existence d'un élément de formulaire (input) ayant le rôle button, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et la valeur spécifiée * */ Then( `je dois voir un bouton nommé {string} avec la valeur {string}`, function(name: string, expectedValue: string) { cy.uuvFindByRole("button", { name: name }) .uuvFoundedElement() .should("exist") .should("have.value", expectedValue); } ); // End of Type Section // Begin of Content Section /** * Vérifie l'existence d'un élément Html ayant le rôle button, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés * */ Then( `je dois voir un bouton nommé {string} et contenant {string}`, function(name: string, expectedTextContent: string) { findWithRoleAndNameAndContent("button", name, expectedTextContent); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle button, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à false * */ Then( `je dois voir un bouton nommé {string} et contenant {string} désactivé`, function(name: string, expectedTextContent: string) { findWithRoleAndNameAndContentDisabled("button", name, expectedTextContent); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle button, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/), le contenu spécifiés et avec l'attribut disabled à true * */ Then( `je dois voir un bouton nommé {string} et contenant {string} activé`, function(name: string, expectedTextContent: string) { findWithRoleAndNameAndContentEnabled("button", name, expectedTextContent); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle button, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à false * */ Then( `je dois voir un bouton nommé {string} désactivé`, function(name: string) { findWithRoleAndNameDisabled("button", name); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle button, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à true * */ Then( `je dois voir un bouton nommé {string} activé`, function(name: string) { findWithRoleAndNameEnabled("button", name); } ); // End of Content Section // Begin of Keyboard Section /** * Vérifie que l'élément Html avec le [rôle accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) a le focus clavier<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/fr-keyboard.feature'>Exemples</a> * */ Then( `je dois voir un bouton nommé {string} avoir le focus clavier`, function(name: string) { findWithRoleAndNameFocused("button", name); } ); /** * Se déplace au précédent élément HTML atteignable avec la tabulation et vérifie que l'élément Html avec le [rôle accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) a le focus clavier<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/fr-keyboard.feature'>Exemples</a> * */ Then( `le précédent élément avec le focus clavier doit être un bouton nommé {string}`, function(name: string) { pressKey("{reverseTab}"); findWithRoleAndNameFocused("button", name); } ); /** * Se déplace au prochain élément HTML atteignable avec la tabulation et vérifie que l'élément Html avec le [rôle accessible](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) a le focus clavier<br/><a target='_blank' href='https://github.com/e2e-test-quest/uuv/blob/main/example/fr-keyboard.feature'>Exemples</a> * */ Then( `le prochain élément avec le focus clavier doit être un bouton nommé {string}`, function(name: string) { pressKey("{tab}"); findWithRoleAndNameFocused("button", name); } ); // End of Keyboard Section