https://cypress.io logo
(PayPal Sandbox) Testing PayPal payment methods in...
# i-need-help
f
I'm testing multiple payment methods in a checkout flow, focusing on PayPal for now. I was able to determine that - PayPal opens a new browser window with an iframe for the end-user to finish authentication and authorize payment - Cypress can't just capture that URL from the iframe and visit that page, as there's some sort of security PayPal implemented that doesn't allow you to finish the flow in anything outside of the provided small pop-up browser window with the iframe. I started following along here: https://whattodevnow.medium.com/testing-paypal-checkout-flow-with-cypress-6c0ebd1321ff I'm having issues right off the bat. In commands.js, I'm using the following:
Copy code
Cypress.Commands.add("popup", () => {
  const popup = Cypress.$(state.popup.document);
  return cy.wrap(popup.contents().find("body"));
});
and when I run the tests as described in the above tutorial, I'm getting the following:
Cannot read properties of undefined (reading 'document')
Has anyone had more success implementing coverage for PayPal checkout options? Is there a better method I could use?
e
I have tests for plaid processing where they do the same, and Im just handling the iframe within there. Have you tried just directly working with the iframe itself?
Im using a plugin that makes it easier: https://www.npmjs.com/package/cypress-iframe
f
That would normally work, and if it was an iframe in the same browser page I'd be okay. The problem is that PayPal opens a new browser window and puts the iframe in there, which is outside of Cypress's reach.

https://cdn.discordapp.com/attachments/1102652510533070919/1102655650061897859/screen_shot_2023-05-01_at_1.png

I currently operate within iframes regularly, but the hangup is that this is a detatched browser window separate from the cypress controlled browser window
e
Oh gotcha. Does that button to open that have an attribute for opening the new page that you can remove? Something like
cy.get('a').invoke('removeAttr', 'target').click()
f
If I try to capture the window open event and take the URL, and have the Cypress controlled browser window navigate there, it lets me sign in, then hits me with a PayPal related error that looks like the attached image. > cy.get('a').invoke('removeAttr', 'target').click() Lemme ping my devs, that's a good lead!

https://cdn.discordapp.com/attachments/1102652510533070919/1102656293329711265/image.png

e
Looks like someone may have solved this with
cy.origin()
https://github.com/cypress-io/cypress/issues/22186#issuecomment-1242240154
f
Okay, so it's not possible yet using
cy.origin()
, but Soon™
2 Views