@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.27 kB
text/typescript
/*******************************
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 complementary 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 complémentaire nommé {string}`, async function(name: string) {
return await withinRoleAndName(this, "complementary", name);
});
/**
* Vérifie l'existence d'un élément Html ayant le rôle complementary et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
* */
Then(`je dois voir un complémentaire nommé {string}`, async function(name: string) {
await findWithRoleAndName(this, "complementary", name);
});
/**
* Vérifie l'inexistence d'un élément Html ayant le rôle complementary et le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) spécifiés
* */
Then(
`je ne dois pas voir un complémentaire nommé {string}`,
async function(name: string) {
await notFoundWithRoleAndName(this, "complementary", 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 le complémentaire nommé {string}`, async function(textToType: string, name: string) {
await getPageOrElement(this).then(async (element) => {
const byRole = await element.getByRole("complementary", { 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 le complémentaire nommé {string}`, async function(textToType: string, name: string) {
await getPageOrElement(this).then(async (element) => {
const byRole = await element.getByRole("complementary", { 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 un complémentaire nommé {string} avec la valeur {string}`, async function(name: string, expectedValue: string) {
await getPageOrElement(this).then(async (element) => {
const byRole = await element.getByRole("complementary", { 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 complementary, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et le contenu spécifiés
* */
Then(
`je dois voir un complémentaire nommé {string} et contenant {string}`,
async function(name: string, expectedTextContent: string) {
await findWithRoleAndNameAndContent(this, "complementary", name, expectedTextContent);
}
);
/**
* Vérifie l'existence d'un élément Html ayant le rôle complementary, 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 complémentaire nommé {string} et contenant {string} désactivé`,
async function(name: string, expectedTextContent: string) {
await findWithRoleAndNameAndContentDisabled(this, "complementary", name, expectedTextContent);
}
);
/**
* Vérifie l'existence d'un élément Html ayant le rôle complementary, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à false
* */
Then(
`je dois voir un complémentaire nommé {string} désactivé`,
async function(name: string) {
await findWithRoleAndNameDisabled(this, "complementary", name);
}
);
/**
* Vérifie l'existence d'un élément Html ayant le rôle complementary, 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 complémentaire nommé {string} et contenant {string} activé`,
async function(name: string, expectedTextContent: string) {
await findWithRoleAndNameAndContentEnabled(this, "complementary", name, expectedTextContent);
}
);
/**
* Vérifie l'existence d'un élément Html ayant le rôle complementary, le [nom accessible](https://russmaxdesign.github.io/html-elements-names/) et avec l'attribut disabled à true
* */
Then(
`je dois voir un complémentaire nommé {string} activé`,
async function(name: string) {
await findWithRoleAndNameEnabled(this, "complementary", name);
}
);
// End of Content Section