Skip to content

Commit 90c932a

Browse files
pixincreatehyperswitch-bot[bot]likhinbopanna
authored
fix(cypress): address cybersource redirection inconsistency (#7057)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: likhinbopanna <[email protected]>
1 parent ccfe6d8 commit 90c932a

File tree

6 files changed

+74
-17
lines changed

6 files changed

+74
-17
lines changed

.github/workflows/cypress-tests-runner.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414
CARGO_INCREMENTAL: 0
1515
CARGO_NET_RETRY: 10
1616
PAYMENTS_CONNECTORS: "cybersource stripe"
17-
PAYOUTS_CONNECTORS: "adyenplatform wise"
17+
PAYOUTS_CONNECTORS: "wise"
1818
RUST_BACKTRACE: short
1919
RUSTUP_MAX_RETRIES: 10
2020
RUN_TESTS: ${{ ((github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name)) || (github.event_name == 'merge_group')}}
@@ -149,7 +149,7 @@ jobs:
149149
run: |
150150
LOCAL_ADMIN_API_KEY=$(yq '.secrets.admin_api_key' ${TOML_PATH})
151151
echo "CYPRESS_ADMINAPIKEY=${LOCAL_ADMIN_API_KEY}" >> $GITHUB_ENV
152-
152+
153153
- name: Install mold linker
154154
if: ${{ runner.os == 'Linux' && env.RUN_TESTS == 'true' }}
155155
uses: rui314/setup-mold@v1

cypress-tests/.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# Mac OS files
12
.DS_Store
3+
4+
# Output files
5+
reports/
6+
screenshots/
7+
videos/
8+
29
creds.json
3-
reports
410
run_all.sh
5-
screenshots

cypress-tests/cypress.config.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from "cypress";
22
import mochawesome from "cypress-mochawesome-reporter/plugin.js";
3+
import fs from "fs";
34

45
let globalState;
56

@@ -28,7 +29,18 @@ export default defineConfig({
2829
return null;
2930
},
3031
});
31-
32+
on("after:spec", (spec, results) => {
33+
if (results && results.video) {
34+
// Do we have failures for any retry attempts?
35+
const failures = results.tests.some((test) =>
36+
test.attempts.some((attempt) => attempt.state === "failed")
37+
);
38+
if (!failures) {
39+
// delete the video if the spec passed and no tests retried
40+
fs.unlinkSync(results.video);
41+
}
42+
}
43+
});
3244
return config;
3345
},
3446
experimentalRunAllSpecs: true,
@@ -47,5 +59,8 @@ export default defineConfig({
4759
chromeWebSecurity: false,
4860
defaultCommandTimeout: 10000,
4961
pageLoadTimeout: 20000,
62+
responseTimeout: 30000,
5063
screenshotsFolder: screenshotsFolderName,
64+
video: true,
65+
videoCompression: 32,
5166
});

cypress-tests/cypress/e2e/PaymentUtils/Cybersource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const successfulNo3DSCardDetails = {
1212
};
1313

1414
const successfulThreeDSTestCardDetails = {
15-
card_number: "4000000000001091",
15+
card_number: "4000000000002701",
1616
card_exp_month: "01",
1717
card_exp_year: "50",
1818
card_holder_name: "joseph Doe",
@@ -79,7 +79,7 @@ const payment_method_data_no3ds = {
7979

8080
const payment_method_data_3ds = {
8181
card: {
82-
last4: "1091",
82+
last4: "2701",
8383
card_type: "CREDIT",
8484
card_network: "Visa",
8585
card_issuer: "INTL HDQTRS-CENTER OWNED",

cypress-tests/cypress/support/e2e.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ import "./commands";
1919

2020
// Alternatively you can use CommonJS syntax:
2121
// require('./commands')
22+
23+
Cypress.on("uncaught:exception", (err) => {
24+
// returning false here prevents Cypress from failing the test
25+
cy.log(`Unhandled exception: ${err}`);
26+
return false;
27+
});

cypress-tests/cypress/support/redirectionHandler.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,18 @@ function bankRedirectRedirection(
272272
}
273273

274274
cy.then(() => {
275-
verifyReturnUrl(redirection_url, expected_url, verifyUrl);
275+
try {
276+
verifyReturnUrl(redirection_url, expected_url, verifyUrl);
277+
} catch (error) {
278+
cy.log("Error during return URL verification:", error);
279+
throw error;
280+
}
276281
});
277282
}
278283

279284
function threeDsRedirection(redirection_url, expected_url, connectorId) {
280285
cy.visit(redirection_url.href);
286+
281287
if (connectorId === "adyen") {
282288
cy.get("iframe")
283289
.its("0.contentDocument.body")
@@ -286,17 +292,32 @@ function threeDsRedirection(redirection_url, expected_url, connectorId) {
286292
cy.get('input[type="password"]').type("password");
287293
cy.get("#buttonSubmit").click();
288294
});
289-
} else if (
290-
connectorId === "bankofamerica" ||
291-
connectorId === "cybersource" ||
292-
connectorId === "wellsfargo"
293-
) {
295+
} else if (connectorId === "bankofamerica" || connectorId === "wellsfargo") {
296+
// Wait for iframe to be present and visible
294297
cy.get("iframe", { timeout: TIMEOUT })
298+
.should("be.visible")
295299
.its("0.contentDocument.body")
300+
.should("not.be.empty") // Ensure body has content
296301
.within(() => {
297-
cy.get('input[type="text"]').click().type("1234");
298-
cy.get('input[value="SUBMIT"]').click();
302+
// Add retry ability and multiple selector attempts
303+
cy.get(
304+
'input[type="text"], input[type="password"], input[name="challengeDataEntry"]',
305+
{ timeout: TIMEOUT }
306+
)
307+
.should("be.visible")
308+
.should("be.enabled")
309+
.click()
310+
.type("1234");
311+
312+
cy.get('input[value="SUBMIT"], button[type="submit"]', {
313+
timeout: TIMEOUT,
314+
})
315+
.should("be.visible")
316+
.click();
299317
});
318+
} else if (connectorId === "cybersource") {
319+
cy.url({ timeout: TIMEOUT }).should("include", expected_url.origin);
320+
return; // this is mandatory, else refunds section will fail with unhandled promise rejections even though it is handled
300321
} else if (connectorId === "checkout") {
301322
cy.get("iframe", { timeout: TIMEOUT })
302323
.its("0.contentDocument.body")
@@ -381,7 +402,12 @@ function threeDsRedirection(redirection_url, expected_url, connectorId) {
381402
}
382403

383404
cy.then(() => {
384-
verifyReturnUrl(redirection_url, expected_url, true);
405+
try {
406+
verifyReturnUrl(redirection_url, expected_url, true);
407+
} catch (error) {
408+
cy.log("Error during return URL verification:", error);
409+
throw error;
410+
}
385411
});
386412
}
387413

@@ -422,7 +448,12 @@ function upiRedirection(
422448
}
423449

424450
cy.then(() => {
425-
verifyReturnUrl(redirection_url, expected_url, verifyUrl);
451+
try {
452+
verifyReturnUrl(redirection_url, expected_url, verifyUrl);
453+
} catch (error) {
454+
cy.log("Error during return URL verification:", error);
455+
throw error;
456+
}
426457
});
427458
}
428459

0 commit comments

Comments
 (0)