UNPKG

@uuv/playwright

Version:

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

164 lines (140 loc) 6.08 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 { click, COOKIE_NAME, deleteCookieByName, findWithRoleAndName, findWithRoleAndNameAndChecked, findWithRoleAndNameAndContent, findWithRoleAndNameAndContentDisabled, findWithRoleAndNameAndContentEnabled, findWithRoleAndNameAndUnchecked, findWithRoleAndNameDisabled, findWithRoleAndNameEnabled, findWithRoleAndNameFocused, getPageOrElement, getTimeout, notFoundWithRoleAndName, withinRoleAndName } from "../../../core-engine"; import { Then, When } from "../../../../../preprocessor/run/world"; import { expect } from "@playwright/test"; // Begin of General Section /** * Sélectionne l'élément ayant le rôle timer 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 de la minuterie nommée {string}`, async function(name: string) { return await withinRoleAndName(this, "timer", name); }); /** * Vérifie l'existence d'un élément Html ayant le rôle timer et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés * */ Then(`je dois voir une minuterie nommée {string}`, async function(name: string) { await findWithRoleAndName(this, "timer", name); }); /** * Vérifie l'inexistence d'un élément Html ayant le rôle timer et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés * */ Then( `je ne dois pas voir une minuterie nommée {string}`, async function(name: string) { await notFoundWithRoleAndName(this, "timer", name); } ); // End of General 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 la minuterie nommée {string}`, async function(textToType: string, name: string) { await getPageOrElement(this).then(async (element) => { const byRole = await element.getByRole("timer", { name: name, exact: true }); await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) }); await byRole.type(textToType); await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT); }); }); /** * 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 la minuterie nommée {string}`, async function(textToType: string, name: string) { await getPageOrElement(this).then(async (element) => { const byRole = await element.getByRole("timer", { name: name, exact: true }); await expect(byRole).toHaveCount(1); await byRole.type(textToType); await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT); }); }); /** * key.then.element.withRoleAndNameAndValue * */ When(`je dois voir une minuterie nommée {string} avec la valeur {string}`, async function(name: string, expectedValue: string) { await getPageOrElement(this).then(async (element) => { const byRole = await element.getByRole("timer", { name: name, exact: true }); await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) }); await expect(byRole).toHaveValue(expectedValue, { timeout: await getTimeout(this) }); await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT); }); }); // End of Type Section // Begin of Content Section /** * Vérifie l'existence d'un élément Html ayant le rôle timer, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés * */ Then( `je dois voir une minuterie nommée {string} et contenant {string}`, async function(name: string, expectedTextContent: string) { await findWithRoleAndNameAndContent(this, "timer", name, expectedTextContent); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle timer, 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 une minuterie nommée {string} et contenant {string} désactivé`, async function(name: string, expectedTextContent: string) { await findWithRoleAndNameAndContentDisabled(this, "timer", name, expectedTextContent); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle timer, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à false * */ Then( `je dois voir une minuterie nommée {string} désactivé`, async function(name: string) { await findWithRoleAndNameDisabled(this, "timer", name); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle timer, 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 une minuterie nommée {string} et contenant {string} activé`, async function(name: string, expectedTextContent: string) { await findWithRoleAndNameAndContentEnabled(this, "timer", name, expectedTextContent); } ); /** * Vérifie l'existence d'un élément Html ayant le rôle timer, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à true * */ Then( `je dois voir une minuterie nommée {string} activé`, async function(name: string) { await findWithRoleAndNameEnabled(this, "timer", name); } ); // End of Content Section