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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(cypress): verify payment status after payment redirection (#6187)
Ankesh Gupta1d993055d221
diff --git a/cypress-tests/cypress/support/redirectionHandler.js b/cypress-tests/cypress/support/redirectionHandler.jsindex 7c1675690e..a7edf8fb97 100644--- a/cypress-tests/cypress/support/redirectionHandler.js+++ b/cypress-tests/cypress/support/redirectionHandler.js@@ -424,17 +424,99 @@ function upiRedirection(function verifyReturnUrl(redirection_url, expected_url, forward_flow) {if (forward_flow) {- // Handling redirectionif (redirection_url.host.endsWith(expected_url.host)) {- // No CORS workaround needed- cy.window().its("location.origin").should("eq", expected_url.origin);+ cy.wait(WAIT_TIME / 2);++ cy.window()+ .its("location")+ .then((location) => {+ // Check page state before taking screenshots+ cy.document().then((doc) => {+ // 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");+ }+ });++ // For error pages+ 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(`error-page-${Date.now()}`);+ }+ });+ });++ const url_params = new URLSearchParams(location.search);+ const payment_status = url_params.get("status");++ if (+ payment_status !== "failed" &&+ payment_status !== "processing" &&+ 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(+ `Redirection failed with payment status: ${payment_status}`+ );+ }+ });} else {- // Workaround for CORS to allow cross-origin iframecy.origin(expected_url.origin,{ args: { expected_url: expected_url.origin } },({ 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()}`);+ }+ });+ });});}