Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(cypress): uncaught exceptions thrown by `hyperswitch.io` (#7092)

Pa1NarKcf82861e855b
diff --git a/cypress-tests/cypress/support/e2e.js b/cypress-tests/cypress/support/e2e.js
index 7013dc8ddc..eab7b99b62 100644
--- a/cypress-tests/cypress/support/e2e.js
+++ b/cypress-tests/cypress/support/e2e.js
@@ -17,11 +17,14 @@
import "cypress-mochawesome-reporter/register";
import "./commands";
-// Alternatively you can use CommonJS syntax:
-// require('./commands')
+// Add error handling for dynamic imports
+Cypress.on("uncaught:exception", (err, runnable) => {
+ // Log the error details
+ // eslint-disable-next-line no-console
+ console.log(
+ `Error: ${err.message}\nError occurred in: ${runnable.title}\nStack trace: ${err.stack}`
+ );
-Cypress.on("uncaught:exception", (err) => {
- // returning false here prevents Cypress from failing the test
- cy.log(`Unhandled exception: ${err}`);
+ // Return false to prevent the error from failing the test
return false;
});
diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.js
index 2cfa8a1f72..cc9c180b35 100644
--- a/cypress-tests/cypress/support/redirectionHandler.js
+++ b/cypress-tests/cypress/support/redirectionHandler.js
@@ -272,143 +272,150 @@ function bankRedirectRedirection(
}
cy.then(() => {
- try {
- verifyReturnUrl(redirection_url, expected_url, verifyUrl);
- } catch (error) {
- cy.log("Error during return URL verification:", error);
- throw error;
- }
+ verifyReturnUrl(redirection_url, expected_url, verifyUrl);
});
}
function threeDsRedirection(redirection_url, expected_url, connectorId) {
cy.visit(redirection_url.href);
- if (connectorId === "adyen") {
- cy.get("iframe")
- .its("0.contentDocument.body")
- .within(() => {
- cy.get('input[type="password"]').click();
- cy.get('input[type="password"]').type("password");
- cy.get("#buttonSubmit").click();
- });
- } else if (connectorId === "bankofamerica" || connectorId === "wellsfargo") {
- // Wait for iframe to be present and visible
- cy.get("iframe", { timeout: TIMEOUT })
- .should("be.visible")
- .its("0.contentDocument.body")
- .should("not.be.empty") // Ensure body has content
- .within(() => {
- // Add retry ability and multiple selector attempts
- cy.get(
- 'input[type="text"], input[type="password"], input[name="challengeDataEntry"]',
- { timeout: TIMEOUT }
- )
- .should("be.visible")
- .should("be.enabled")
- .click()
- .type("1234");
-
- cy.get('input[value="SUBMIT"], button[type="submit"]', {
- timeout: TIMEOUT,
- })
- .should("be.visible")
- .click();
- });
- } else if (connectorId === "cybersource") {
- cy.url({ timeout: TIMEOUT }).should("include", expected_url.origin);
- return; // this is mandatory, else refunds section will fail with unhandled promise rejections even though it is handled
- } else if (connectorId === "checkout") {
- cy.get("iframe", { timeout: TIMEOUT })
- .its("0.contentDocument.body")
- .within(() => {
- cy.get('form[id="form"]', { timeout: WAIT_TIME })
- .should("exist")
- .then(() => {
- cy.get('input[id="password"]').click();
- cy.get('input[id="password"]').type("Checkout1!");
- cy.get("#txtButton").click();
- });
- });
- } else if (
- connectorId === "nmi" ||
- connectorId === "noon" ||
- connectorId == "xendit"
- ) {
- cy.get("iframe", { timeout: TIMEOUT })
- .its("0.contentDocument.body")
- .within(() => {
- cy.get("iframe", { timeout: TIMEOUT })
- .its("0.contentDocument.body")
- .within(() => {
- cy.get('form[name="cardholderInput"]', { timeout: TIMEOUT })
- .should("exist")
- .then(() => {
- cy.get('input[name="challengeDataEntry"]').click().type("1234");
- cy.get('input[value="SUBMIT"]').click();
- });
- });
- });
- } else if (connectorId === "novalnet") {
- cy.get("form", { timeout: WAIT_TIME })
- .should("exist")
- .then(() => {
- cy.get('input[id="submit"]').click();
- });
- } else if (connectorId === "stripe") {
- cy.get("iframe", { timeout: TIMEOUT })
- .its("0.contentDocument.body")
- .within(() => {
- cy.get("iframe")
- .its("0.contentDocument.body")
- .within(() => {
- cy.get("#test-source-authorize-3ds").click();
- });
- });
- } else if (connectorId === "trustpay") {
- cy.get('form[name="challengeForm"]', { timeout: WAIT_TIME })
- .should("exist")
- .then(() => {
- cy.get("#outcomeSelect").select("Approve").should("have.value", "Y");
- cy.get('button[type="submit"]').click();
- });
- } else if (connectorId === "worldpay") {
- cy.get("iframe", { timeout: WAIT_TIME })
- .its("0.contentDocument.body")
- .within(() => {
- cy.get('form[name="cardholderInput"]', { timeout: WAIT_TIME })
- .should("exist")
- .then(() => {
- cy.get('input[name="challengeDataEntry"]').click().type("1234");
- cy.get('input[value="SUBMIT"]').click();
- });
- });
- } else if (connectorId === "fiuu") {
- cy.get('form[id="cc_form"]', { timeout: TIMEOUT })
- .should("exist")
- .then(() => {
- cy.get('button.pay-btn[name="pay"]').click();
- cy.get("div.otp")
- .invoke("text")
- .then((otpText) => {
- const otp = otpText.match(/\d+/)[0]; // Extract the numeric OTP
- cy.get("input#otp-input").should("not.be.disabled").type(otp);
- cy.get("button.pay-btn").click();
- });
- });
- } else {
- // If connectorId is neither of adyen, trustpay, nmi, stripe, bankofamerica or cybersource, wait for 10 seconds
- cy.wait(WAIT_TIME);
+ switch (connectorId) {
+ case "adyen":
+ cy.get("iframe")
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get('input[type="password"]').click();
+ cy.get('input[type="password"]').type("password");
+ cy.get("#buttonSubmit").click();
+ });
+ break;
+
+ case "bankofamerica":
+ case "wellsfargo":
+ cy.get("iframe", { timeout: TIMEOUT })
+ .should("be.visible")
+ .its("0.contentDocument.body")
+ .should("not.be.empty")
+ .within(() => {
+ cy.get(
+ 'input[type="text"], input[type="password"], input[name="challengeDataEntry"]',
+ { timeout: TIMEOUT }
+ )
+ .should("be.visible")
+ .should("be.enabled")
+ .click()
+ .type("1234");
+
+ cy.get('input[value="SUBMIT"], button[type="submit"]', {
+ timeout: TIMEOUT,
+ })
+ .should("be.visible")
+ .click();
+ });
+ break;
+
+ case "cybersource":
+ cy.url({ timeout: TIMEOUT }).should("include", expected_url.origin);
+ break;
+
+ case "checkout":
+ cy.get("iframe", { timeout: TIMEOUT })
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get('form[id="form"]', { timeout: WAIT_TIME })
+ .should("exist")
+ .then(() => {
+ cy.get('input[id="password"]').click();
+ cy.get('input[id="password"]').type("Checkout1!");
+ cy.get("#txtButton").click();
+ });
+ });
+ break;
+
+ case "nmi":
+ case "noon":
+ case "xendit":
+ cy.get("iframe", { timeout: TIMEOUT })
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get("iframe", { timeout: TIMEOUT })
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get('form[name="cardholderInput"]', { timeout: TIMEOUT })
+ .should("exist")
+ .then(() => {
+ cy.get('input[name="challengeDataEntry"]')
+ .click()
+ .type("1234");
+ cy.get('input[value="SUBMIT"]').click();
+ });
+ });
+ });
+ break;
+
+ case "novalnet":
+ cy.get("form", { timeout: WAIT_TIME })
+ .should("exist")
+ .then(() => {
+ cy.get('input[id="submit"]').click();
+ });
+ break;
+
+ case "stripe":
+ cy.get("iframe", { timeout: TIMEOUT })
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get("iframe")
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get("#test-source-authorize-3ds").click();
+ });
+ });
+ break;
+
+ case "trustpay":
+ cy.get('form[name="challengeForm"]', { timeout: WAIT_TIME })
+ .should("exist")
+ .then(() => {
+ cy.get("#outcomeSelect").select("Approve").should("have.value", "Y");
+ cy.get('button[type="submit"]').click();
+ });
+ break;
+
+ case "worldpay":
+ cy.get("iframe", { timeout: WAIT_TIME })
+ .its("0.contentDocument.body")
+ .within(() => {
+ cy.get('form[name="cardholderInput"]', { timeout: WAIT_TIME })
+ .should("exist")
+ .then(() => {
+ cy.get('input[name="challengeDataEntry"]').click().type("1234");
+ cy.get('input[value="SUBMIT"]').click();
+ });
+ });
+ break;
+
+ case "fiuu":
+ cy.get('form[id="cc_form"]', { timeout: TIMEOUT })
+ .should("exist")
+ .then(() => {
+ cy.get('button.pay-btn[name="pay"]').click();
+ cy.get("div.otp")
+ .invoke("text")
+ .then((otpText) => {
+ const otp = otpText.match(/\d+/)[0];
+ cy.get("input#otp-input").should("not.be.disabled").type(otp);
+ cy.get("button.pay-btn").click();
+ });
+ });
+ break;
+
+ default:
+ cy.wait(WAIT_TIME);
}
- cy.then(() => {
- try {
- verifyReturnUrl(redirection_url, expected_url, true);
- } catch (error) {
- cy.log("Error during return URL verification:", error);
- throw error;
- }
- });
+ // Verify return URL after handling the specific connector
+ verifyReturnUrl(redirection_url, expected_url, true);
}
function upiRedirection(
@@ -448,17 +455,14 @@ function upiRedirection(
}
cy.then(() => {
- try {
- verifyReturnUrl(redirection_url, expected_url, verifyUrl);
- } catch (error) {
- cy.log("Error during return URL verification:", error);
- throw error;
- }
+ verifyReturnUrl(redirection_url, expected_url, verifyUrl);
});
}
function verifyReturnUrl(redirection_url, expected_url, forward_flow) {
- if (forward_flow) {
+ if (!forward_flow) return;
+
+ try {
if (redirection_url.host.endsWith(expected_url.host)) {
cy.wait(WAIT_TIME / 2);
@@ -470,7 +474,6 @@ function verifyReturnUrl(redirection_url, expected_url, forward_flow) {
// For blank page
cy.wrap(doc.body.innerText.trim()).then((text) => {
if (text === "") {
- // Assert before screenshot
cy.wrap(text).should("eq", "");
cy.screenshot("blank-page-error");
}
@@ -488,7 +491,6 @@ function verifyReturnUrl(redirection_url, expected_url, forward_flow) {
const pageText = doc.body.innerText.toLowerCase();
cy.wrap(pageText).then((text) => {
if (errorPatterns.some((pattern) => pattern.test(text))) {
- // Assert the presence of error message
cy.wrap(text).should((content) => {
expect(errorPatterns.some((pattern) => pattern.test(content)))
.to.be.true;
@@ -507,7 +509,6 @@ function verifyReturnUrl(redirection_url, expected_url, forward_flow) {
payment_status !== "requires_capture" &&
payment_status !== "succeeded"
) {
- // Assert payment status before screenshot
cy.wrap(payment_status).should("exist");
cy.screenshot(`failed-payment-${payment_status}`);
throw new Error(
@@ -522,39 +523,21 @@ function verifyReturnUrl(redirection_url, expected_url, forward_flow) {
({ expected_url }) => {
cy.window().its("location.origin").should("eq", expected_url);
- cy.document().then((doc) => {
- // For blank page in cross-origin
- cy.wrap(doc.body.innerText.trim()).then((text) => {
- if (text === "") {
- // Assert before screenshot
- cy.wrap(text).should("eq", "");
- cy.screenshot("cross-origin-blank-page");
- }
- });
-
- const errorPatterns = [
- /4\d{2}/,
- /5\d{2}/,
- /error/i,
- /invalid request/i,
- /server error/i,
- ];
-
- const pageText = doc.body.innerText.toLowerCase();
- cy.wrap(pageText).then((text) => {
- if (errorPatterns.some((pattern) => pattern.test(text))) {
- // Assert the presence of error message
- cy.wrap(text).should((content) => {
- expect(errorPatterns.some((pattern) => pattern.test(content)))
- .to.be.true;
- });
- cy.screenshot(`cross-origin-error-${Date.now()}`);
- }
- });
+ Cypress.on("uncaught:exception", (err, runnable) => {
+ // Log the error details
+ // eslint-disable-next-line no-console
+ console.log(
+ `Error: ${err.message}\nError occurred in: ${runnable.title}\nStack trace: ${err.stack}`
+ );
+ // Return false to prevent the error from failing the test
+ return false;
});
}
);
}
+ } catch (error) {
+ cy.error("Redirection verification failed:", error);
+ throw error;
}
}
diff --git a/cypress-tests/package-lock.json b/cypress-tests/package-lock.json
index 9fb61a5da8..57aef9f3b3 100644
--- a/cypress-tests/package-lock.json
+++ b/cypress-tests/package-lock.json
@@ -9,13 +9,13 @@
"version": "1.0.0",
"license": "ISC",
"devDependencies": {
- "@eslint/js": "^9.17.0",
+ "@eslint/js": "^9.18.0",
"cypress": "^13.17.0",
"cypress-mochawesome-reporter": "^3.8.2",
- "eslint": "^9.17.0",
- "eslint-config-prettier": "^9.1.0",
+ "eslint": "^9.18.0",
+ "eslint-config-prettier": "^10.0.1",
"eslint-plugin-cypress": "^4.1.0",
- "eslint-plugin-prettier": "^5.2.1",
+ "eslint-plugin-prettier": "^5.2.3",
"globals": "^15.14.0",
"jsqr": "^1.4.0",
"prettier": "^3.4.2"
@@ -141,11 +141,14 @@
}
},
"node_modules/@eslint/core": {
- "version": "0.9.0",
- "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.9.0.tgz",
- "integrity": "sha512-7ATR9F0e4W85D/0w7cU0SNj7qkAexMG+bAHEZOjo9akvGuhHE2m7umzWzfnpa0XAg5Kxc1BWmtPMV67jJ+9VUg==",
+ "version": "0.10.0",
+ "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.10.0.tgz",
+ "integrity": "sha512-gFHJ+xBOo4G3WRlR1e/3G8A6/KZAH6zcE/hkLRCZTi/B9avAG365QhFA8uOGzTMqgTghpn7/fSnscW++dpMSAw==",
"dev": true,
"license": "Apache-2.0",
+ "dependencies": {
+ "@types/json-schema": "^7.0.15"
+ },
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
@@ -188,9 +191,9 @@
}
},
"node_modules/@eslint/js": {
- "version": "9.17.0",
- "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.17.0.tgz",
- "integrity": "sha512-Sxc4hqcs1kTu0iID3kcZDW3JHq2a77HO9P8CP6YEA/FpH3Ll8UXE2r/86Rz9YJLKme39S9vU5OWNjC6Xl0Cr3w==",
+ "version": "9.18.0",
+ "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.18.0.tgz",
+ "integrity": "sha512-fK6L7rxcq6/z+AaQMtiFTkvbHkBLNlwyRxHpKawP0x3u9+NC6MQTnFW+AdpwC6gfHTW0051cokQgtTN2FqlxQA==",
"dev": true,
"license": "MIT",
"engines": {
@@ -208,12 +211,13 @@
}
},
"node_modules/@eslint/plugin-kit": {
- "version": "0.2.3",
- "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.3.tgz",
- "integrity": "sha512-2b/g5hRmpbb1o4GnTZax9N9m0FXzz9OV42ZzI4rDDMDuHUqigAiQCEWChBWCY4ztAGVRjoWT19v0yMmc5/L5kA==",
+ "version": "0.2.5",
+ "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.5.tgz",
+ "integrity": "sha512-lB05FkqEdUg2AA0xEbUz0SnkXT1LcCTa438W4IWTUh4hdOnVbQyOJ81OrDXsJk/LSiJHubgGEFoR5EHq1NsH1A==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
+ "@eslint/core": "^0.10.0",
"levn": "^0.4.1"
},
"engines": {
@@ -1331,19 +1335,19 @@
}
},
"node_modules/eslint": {
- "version": "9.17.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.17.0.tgz",
- "integrity": "sha512-evtlNcpJg+cZLcnVKwsai8fExnqjGPicK7gnUtlNuzu+Fv9bI0aLpND5T44VLQtoMEnI57LoXO9XAkIXwohKrA==",
+ "version": "9.18.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.18.0.tgz",
+ "integrity": "sha512-+waTfRWQlSbpt3KWE+CjrPPYnbq9kfZIYUqapc0uBXyjTp8aYXZDsUH16m39Ryq3NjAVP4tjuF7KaukeqoCoaA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.12.1",
"@eslint/config-array": "^0.19.0",
- "@eslint/core": "^0.9.0",
+ "@eslint/core": "^0.10.0",
"@eslint/eslintrc": "^3.2.0",
- "@eslint/js": "9.17.0",
- "@eslint/plugin-kit": "^0.2.3",
+ "@eslint/js": "9.18.0",
+ "@eslint/plugin-kit": "^0.2.5",
"@humanfs/node": "^0.16.6",
"@humanwhocodes/module-importer": "^1.0.1",
"@humanwhocodes/retry": "^0.4.1",
@@ -1391,13 +1395,13 @@
}
},
"node_modules/eslint-config-prettier": {
- "version": "9.1.0",
- "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz",
- "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==",
+ "version": "10.0.1",
+ "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.0.1.tgz",
+ "integrity": "sha512-lZBts941cyJyeaooiKxAtzoPHTN+GbQTJFAIdQbRhA4/8whaAraEh47Whw/ZFfrjNSnlAxqfm9i0XVAEkULjCw==",
"dev": true,
"license": "MIT",
"bin": {
- "eslint-config-prettier": "bin/cli.js"
+ "eslint-config-prettier": "build/bin/cli.js"
},
"peerDependencies": {
"eslint": ">=7.0.0"
@@ -1417,9 +1421,9 @@
}
},
"node_modules/eslint-plugin-prettier": {
- "version": "5.2.1",
- "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz",
- "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==",
+ "version": "5.2.3",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.3.tgz",
+ "integrity": "sha512-qJ+y0FfCp/mQYQ/vWQ3s7eUlFEL4PyKfAJxsnYTJ4YT73nsJBWqmEpFryxV9OeUiqmsTsYJ5Y+KDNaeP31wrRw==",
"dev": true,
"license": "MIT",
"dependencies": {
diff --git a/cypress-tests/package.json b/cypress-tests/package.json
index 7032a72fb0..2f2f2c692c 100644
--- a/cypress-tests/package.json
+++ b/cypress-tests/package.json
@@ -19,13 +19,13 @@
"author": "Hyperswitch",
"license": "ISC",
"devDependencies": {
- "@eslint/js": "^9.17.0",
+ "@eslint/js": "^9.18.0",
"cypress": "^13.17.0",
"cypress-mochawesome-reporter": "^3.8.2",
- "eslint": "^9.17.0",
- "eslint-config-prettier": "^9.1.0",
+ "eslint": "^9.18.0",
+ "eslint-config-prettier": "^10.0.1",
"eslint-plugin-cypress": "^4.1.0",
- "eslint-plugin-prettier": "^5.2.1",
+ "eslint-plugin-prettier": "^5.2.3",
"globals": "^15.14.0",
"jsqr": "^1.4.0",
"prettier": "^3.4.2"