UNPKG

cypress-enterprise-commands

Version:

Reusable Cypress custom commands for enterprise web applications

56 lines (55 loc) 2.54 kB
"use strict"; Cypress.Commands.add("verifyDimmidInput", (attr) => { cy.getByTestAttribute(attr).then(($input) => { cy.softAssertElement($input, "be.disabled", `Input ${attr} should be disabled`); }); }); Cypress.Commands.add("verifyDimmidReadOnlyInput", (attr) => { cy.getByTestAttribute(attr).then(($input) => { cy.softAssertElement($input, "have.attr", "readonly", `Input ${attr} should be readonly`); cy.softAssertElement($input, "be.disabled", `Input ${attr} should be disabled`); }); }); Cypress.Commands.add("verifyNotDimmidInput", (attr) => { cy.getByTestAttribute(attr).then(($input) => { cy.softAssertElement($input, "not.have.attr", "readonly", `Input ${attr} should not be readonly`); cy.softAssertElement($input, "not.have.attr", "disabled", `Input ${attr} should not be disabled`); }); }); // Dropdown list verification Cypress.Commands.add("verifyDimmidItemDropDownList", (attr) => { cy.catchUnCaughtException(); cy.getByTestAttribute(attr).click({ multiple: true, force: true }); cy.get('[role="listbox"]').should("not.exist"); }); Cypress.Commands.add("verifyNotExistanceTheRequiredValidation", () => { cy.ensurePageIsReady(); cy.get("span.errorMessage").should("not.exist"); }); Cypress.Commands.add("verifyDisplayingTheRequiredValidationMsgsCount", (cout) => { cy.get("span.errorMessage").last().scrollIntoView(); cy.get("span.errorMessage").should("have.length", cout); }); Cypress.Commands.add("visibilityOfRequiredStar", (fieldSelector) => { cy.get(fieldSelector).should("contain", "*"); }); Cypress.Commands.add("checkImageVisibilityBySrc", (imgSrc) => { cy.get("img[src=" + imgSrc + "]").should("be.visible"); }); Cypress.Commands.add("isSwitchedOn", (index, isSwitchedOn) => { cy.softAssert(() => { cy.get('input[type="checkbox"]') .eq(index) .scrollIntoView() .should("have.attr", "aria-checked", isSwitchedOn ? "true" : "false"); }, `isSwitchedOn should be ${isSwitchedOn}`); }); Cypress.Commands.add("verifyAfterSavingBehavior", () => { cy.ensurePageIsReady(); cy.get('body').then(($body) => { const cancelButtons = $body.find('button:contains("Cancel"), button:contains("Back") '); cy.wrap(cancelButtons.last()).should('exist').should('be.visible', { timeout: 20000 }); }); cy.contains("button", /edit/i, { timeout: 20000 }).scrollIntoView().should("be.visible"); cy.url().should("include", "view", { timeout: 25000 }); });