Reputation:
I am using cypress v5.4 to test braintree paypal dropin with test visa card but unable to locate into iframe. Since cypress doesn't provide a native way to deal with iframes hence I am creating a custom command, basically to traverse through an iframe. But it doesn't work.
here is how command.js
looks like.
Cypress.Commands.add('getIframeBody', () => {
return cy
.get('#braintree-hosted-field-number')
.its('0.contentDocument.body')
.should('not.be.empty')
.then(cy.wrap)
});
And here is my test paymentMethods.js
cy.get(".braintree-option.braintree-option__card")
.should("be.visible")
.click()
cy.get("div.ModalContent__BottomSection-b9lci0-1", {timeout:5000})
cy.getIframeBody()
.find('#credit-card-number').type('4111111111111111');
It stuck when wrapping iframe into cypress
HTML:
All help will be appreciated, thank you.
Upvotes: 1
Views: 714
Reputation: 18650
I would suggest you use the cypress iframe plugin.
To install use the command npm install -D cypress-iframe
.
In your cypress/support/commands.js
file, add the following:
import 'cypress-iframe'
// or
require('cypress-iframe')
cy.iframe('#braintree-hosted-field-number')
.find('#credit-card-number')
.type('4111111111111111')
Upvotes: 2