cypress-enterprise-commands
Version:
Reusable Cypress custom commands for enterprise web applications
78 lines (77 loc) • 2.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", () => {
Cypress.on("uncaught:exception", (err, runnable) => {
const knownNonCriticalErrors = [
"Cannot read properties of null",
"Cannot read properties of undefined",
"reading 'children'",
"reading 'split'",
"is not a function",
"undefined is not iterable",
"undefined is not an object",
"is not defined",
"ResizeObserver loop limit exceeded", // Chrome quirk
];
const shouldIgnore = knownNonCriticalErrors.some((msg) => err.message.includes(msg));
if (shouldIgnore) {
Cypress.log({
name: "⚠️ Ignored uncaught exception",
message: err.message,
consoleProps: () => ({
error: err,
test: runnable?.title,
}),
});
return false; // prevent test from failing
}
// Otherwise, let the test fail
Cypress.log({
name: "🔥 Unhandled uncaught exception",
message: err.message,
consoleProps: () => ({
error: err,
test: runnable?.title,
}),
});
return true; // fail the test
});
});