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

140 lines (139 loc) 4.91 kB
"use strict"; /** * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.assertTextContent = assertTextContent; exports.findWithRoleAndName = findWithRoleAndName; exports.findWithRoleAndNameFocused = findWithRoleAndNameFocused; exports.withinRoleAndName = withinRoleAndName; exports.notFoundWithRoleAndName = notFoundWithRoleAndName; exports.findWithRoleAndNameAndContent = findWithRoleAndNameAndContent; exports.findWithRoleAndNameAndContentDisabled = findWithRoleAndNameAndContentDisabled; exports.findWithRoleAndNameDisabled = findWithRoleAndNameDisabled; exports.findWithRoleAndNameAndContentEnabled = findWithRoleAndNameAndContentEnabled; exports.findWithRoleAndNameEnabled = findWithRoleAndNameEnabled; exports.findWithRoleAndNameAndAttribute = findWithRoleAndNameAndAttribute; exports.click = click; const _context_1 = require("./_context"); const __common_1 = require("./_.common"); beforeEach(function () { cy.wrap(new _context_1.Context()).as("context"); }); after(function () { if ((0, __common_1.shouldGenerateA11yReport)()) { // cy.showUvvA11yReport(A11yReferenceEnum.RGAA); } return null; }); function assertTextContent(response, expectedTextContent) { try { assert.equal(response[0].textContent, expectedTextContent); } catch (e) { /* eslint-disable @typescript-eslint/no-explicit-any */ assert.equal(response[0].value, expectedTextContent); } } function findWithRoleAndName(role, name) { findByRoleAndName(role, name); } function findWithRoleAndNameFocused(role, name) { findByRoleAndName(role, name) .then(foundElement => { cy.focused().then(focusedElement => { expect(foundElement?.get(0)).eq(focusedElement?.get(0)); }); }); } function withinRoleAndName(role, name) { const foundedElement = cy.uuvFindByRole(role, { name, hidden: true }) .uuvFoundedElement() .should("exist"); cy.uuvPatchContext({ withinFocusedElement: foundedElement }); } function notFoundWithRoleAndName(role, name) { cy.uuvFindByRole(role, { name }) .should("not.exist"); } function findWithRoleAndNameAndContent(expectedRole, name, expectedTextContent) { cy.uuvFindByRole(expectedRole, { name }) .uuvFoundedElement() .should("exist") .then((response) => { assert.equal(response.length, 1); assertTextContent(response, expectedTextContent); }); } function findWithRoleAndNameAndContentDisabled(expectedRole, name, expectedTextContent) { cy.uuvFindByRole(expectedRole, { name }) .uuvFoundedElement() .should("exist") .then((response) => { assert.equal(response.length, 1); assertTextContent(response, expectedTextContent); }) .invoke("attr", "disabled") .should("eq", "disabled"); } function findWithRoleAndNameDisabled(expectedRole, name) { cy.uuvFindByRole(expectedRole, { name }) .uuvFoundedElement() .should("exist") .invoke("attr", "disabled") .should("eq", "disabled"); } function findWithRoleAndNameAndContentEnabled(expectedRole, name, expectedTextContent) { cy.uuvFindByRole(expectedRole, { name }) .uuvFoundedElement() .should("exist") .then((response) => { assert.equal(response.length, 1); assertTextContent(response, expectedTextContent); }) .invoke("attr", "disabled") .should("eq", undefined); } function findWithRoleAndNameEnabled(expectedRole, name) { cy.uuvFindByRole(expectedRole, { name }) .uuvFoundedElement() .should("exist") .invoke("attr", "disabled") .should("eq", undefined); } function findWithRoleAndNameAndAttribute(expectedRole, name, attributeName, attributeValue) { cy.uuvFindByRole(expectedRole, { name }) .uuvFoundedElement() .should("exist") .then((elements) => { assert.equal(elements[0][attributeName], attributeValue); }); } function findByRoleAndName(role, name) { return cy.uuvFindByRole(role, { name }) .uuvFoundedElement() .should("exist"); } function click(role, name) { cy.uuvGetContext().then(context => { const parentElement = context.withinFocusedElement; if (parentElement) { cy.uuvFindByRole(role, { name: name }).uuvFoundedElement().click(); cy.wrap(new _context_1.Context()).as("context"); } else { cy.findByRole(role, { name: name, ...context }).click(); } }); }