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.61 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 /** * Selects the element whose [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and accessible [name](https://russmaxdesign.github.io/html-elements-names/) are specified <br />⚠ remember to deselect the element with <b>[I reset context](#i-reset-context)</b> if you're no longer acting on it * */ When(`within a command named {string}`, async function(name: string) { return await withinRoleAndName(this, "command", name); }); /** * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/) * */ Then(`I should see a command named {string}`, async function(name: string) { await findWithRoleAndName(this, "command", name); }); /** * Checks that an Html element does not exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types) and [name](https://russmaxdesign.github.io/html-elements-names/) * */ Then( `I should not see a command named {string}`, async function(name: string) { await notFoundWithRoleAndName(this, "command", name); } ); // End of General Section // Begin of Type Section /** * Writes the sentence given as a parameter inside the specified field (useful for example to fill in a form field) * */ When(`I type the sentence {string} in the command named {string}`, async function(textToType: string, name: string) { await getPageOrElement(this).then(async (element) => { const byRole = await element.getByRole("command", { name: name, exact: true }); await expect(byRole).toHaveCount(1, { timeout: await getTimeout(this) }); await byRole.type(textToType); await deleteCookieByName(this, COOKIE_NAME.SELECTED_ELEMENT); }); }); /** * Writes the sentence given as a parameter inside the specified field (useful for example to fill in a form field) * */ When(`I enter the value {string} in the command named {string}`, async function(textToType: string, name: string) { await getPageOrElement(this).then(async (element) => { const byRole = await element.getByRole("command", { 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(`I should see a command named {string} with value {string}`, async function(name: string, expectedValue: string) { await getPageOrElement(this).then(async (element) => { const byRole = await element.getByRole("command", { 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 /** * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content * */ Then( `I should see a command named {string} and containing {string}`, async function(name: string, expectedTextContent: string) { await findWithRoleAndNameAndContent(this, "command", name, expectedTextContent); } ); /** * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content, and with the disabled attribute set to true * */ Then( `I should see a command named {string} and containing {string} disabled`, async function(name: string, expectedTextContent: string) { await findWithRoleAndNameAndContentDisabled(this, "command", name, expectedTextContent); } ); /** * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/), and with the disabled attribute set to true * */ Then( `I should see a command named {string} disabled`, async function(name: string) { await findWithRoleAndNameDisabled(this, "command", name); } ); /** * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/) and content, and with the disabled attribute set to false * */ Then( `I should see a command named {string} and containing {string} enabled`, async function(name: string, expectedTextContent: string) { await findWithRoleAndNameAndContentEnabled(this, "command", name, expectedTextContent); } ); /** * Checks that an Html element exists with the specified [accessible role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles#aria_role_types), [name](https://russmaxdesign.github.io/html-elements-names/), and with the disabled attribute set to false * */ Then( `I should see a command named {string} enabled`, async function(name: string) { await findWithRoleAndNameEnabled(this, "command", name); } ); // End of Content Section