cypress-enterprise-commands
Version:
Reusable Cypress custom commands for enterprise web applications
50 lines (49 loc) • 1.81 kB
JavaScript
;
Cypress.Commands.add("logMsg", (str) => {
cy.log("*****" + str + "*****");
});
Cypress.Commands.add("getAllItemsCount", (gridSelector, itemSelector) => {
cy.ensurePageIsReady();
cy.get("body").then(($body) => {
if ($body.find(gridSelector).is(":visible")) {
cy.get(gridSelector).then((parent) => {
if (parent.find(itemSelector).is(":visible")) {
cy.get(gridSelector).find(itemSelector).last().scrollIntoView();
// Get the count of items and return it
return cy
.get(gridSelector)
.find(itemSelector)
.its("length")
.then((updatedCount) => {
return updatedCount; // Return the count directly
});
}
else {
cy.log("The Main gridSelector is not visible");
return 0;
}
});
}
else {
cy.log("The Main gridSelector is not visible");
}
});
});
Cypress.Commands.add("hideDialogFooter", () => {
cy.get(".pop_up_footer").invoke("hide");
});
Cypress.Commands.add("displayDialogFooter", () => {
cy.get(".pop_up_footer").invoke("css", "display", "block");
});
Cypress.Commands.add("getByTestAttribute", (el) => {
return cy.get("[data-testid=" + el + "]", { timeout: 30000 });
});
Cypress.Commands.add("catchUnCaughtException", () => {
// Catch uncaught exceptions specific to the "children" error
Cypress.on("uncaught:exception", (err) => {
if (err.message.includes("Cannot read properties of null (reading 'children')")) {
return false;
}
return true;
});
});