From 278f1b5d899002a760abed59e9a9c84f224dde01 Mon Sep 17 00:00:00 2001 From: shubhamchasing Date: Thu, 24 Oct 2024 07:26:35 +0530 Subject: [PATCH] feat: add getIframeElement for accessing iframe elements --- cypress-tests/cypress/support/commands.ts | 63 +++++++++++++--------- cypress-tests/cypress/support/types.ts | 66 ++++++++++++++--------- 2 files changed, 79 insertions(+), 50 deletions(-) diff --git a/cypress-tests/cypress/support/commands.ts b/cypress-tests/cypress/support/commands.ts index 5a3fe36e2..c3d965cd5 100644 --- a/cypress-tests/cypress/support/commands.ts +++ b/cypress-tests/cypress/support/commands.ts @@ -24,7 +24,7 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) import "cypress-iframe"; -import { createPaymentBody } from "./utils" +import { createPaymentBody } from "./utils"; import * as testIds from "../../../src/Utilities/TestUtils.bs"; // commands.js or your custom support file const iframeSelector = @@ -146,30 +146,45 @@ Cypress.Commands.add( } ); - -Cypress.Commands.add("createPaymentIntent", (secretKey: string, createPaymentBody: any) => { - return cy - .request({ - method: "POST", - url: "https://sandbox.hyperswitch.io/payments", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "api-key": secretKey, - }, - body: JSON.stringify(createPaymentBody), - }) - .then((response) => { - expect(response.headers["content-type"]).to.include("application/json"); - expect(response.body).to.have.property("client_secret"); - const clientSecret = response.body.client_secret; - cy.log(clientSecret); - cy.log(response.toString()); - - globalState["clientSecret"] = clientSecret; - }); -}); +Cypress.Commands.add( + "createPaymentIntent", + (secretKey: string, createPaymentBody: any) => { + return cy + .request({ + method: "POST", + url: "https://sandbox.hyperswitch.io/payments", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": secretKey, + }, + body: JSON.stringify(createPaymentBody), + }) + .then((response) => { + expect(response.headers["content-type"]).to.include("application/json"); + expect(response.body).to.have.property("client_secret"); + const clientSecret = response.body.client_secret; + cy.log(clientSecret); + cy.log(response.toString()); + + globalState["clientSecret"] = clientSecret; + }); + } +); Cypress.Commands.add("getGlobalState", (key: any) => { return globalState[key]; }); + +Cypress.Commands.add( + "getIframeElement", + (iframeSelector, elementSelector) => { + return cy + .get(iframeSelector) + .its("0.contentDocument.body") + .should("not.be.empty") + .then(cy.wrap) + .find(elementSelector) + .should("be.visible"); + } +); diff --git a/cypress-tests/cypress/support/types.ts b/cypress-tests/cypress/support/types.ts index d1db388d1..fd5b74ec3 100644 --- a/cypress-tests/cypress/support/types.ts +++ b/cypress-tests/cypress/support/types.ts @@ -1,31 +1,45 @@ - -export { }; // indicate that file is a module +export {}; // indicate that file is a module export type CustomerData = { - cardNo: string - cardExpiry: string - cardCVV: string - cardHolderName: string - email: string - address: string - city: string - country: string - state: string - postalCode: string - threeDSCardNo: string -} + cardNo: string; + cardExpiry: string; + cardCVV: string; + cardHolderName: string; + email: string; + address: string; + city: string; + country: string; + state: string; + postalCode: string; + threeDSCardNo: string; +}; declare global { - namespace Cypress { - interface Chainable { - enterValueInIframe(selector: string, value: string): Chainable> - selectValueInIframe(selector: string, value: string): Chainable> - hardReload(): Chainable> - testDynamicFields( - customerData: CustomerData, testIdsToRemoveArr: string[], isThreeDSEnabled: boolean - ): Chainable> - createPaymentIntent(secretKey: string, createPaymentBody: Record): Chainable> - getGlobalState(key: string): Chainable> - } + namespace Cypress { + interface Chainable { + enterValueInIframe( + selector: string, + value: string + ): Chainable>; + selectValueInIframe( + selector: string, + value: string + ): Chainable>; + hardReload(): Chainable>; + testDynamicFields( + customerData: CustomerData, + testIdsToRemoveArr: string[], + isThreeDSEnabled: boolean + ): Chainable>; + createPaymentIntent( + secretKey: string, + createPaymentBody: Record + ): Chainable>; + getGlobalState(key: string): Chainable>; + getIframeElement( + iframeSelector: string, + elementSelector: string + ): Chainable>; } -} \ No newline at end of file + } +}