How do I enter data into a form input in an iframe using cypress?

后端 未结 8 1765
渐次进展
渐次进展 2021-02-05 14:01

I have been trying to test a stripe checkout form using cypress.io

If anyone has managed to get this to work please let me know. I found a thread on the matter here http

8条回答
  •  轮回少年
    2021-02-05 14:16

    This doesn't directly answer your question, but after several days of trying to wrangle manipulating elements in the iframe using jQuery, re-implementing a bunch of stuff that Cypress already did, I smacked myself and started doing this:

    Cypress.Commands.add('openiframe', () => {
        return cy.get("iframe[src^='/']").then(iframe => {
            cy.visit(Cypress.$(iframe).attr('src'), { timeout: Cypress.config("pageLoadTimeout") });
        });
    });
    

    That allowed me to just cy.openiframe().then(() => {}); and proceed as if the site I was testing didn't put a bunch of functionality in an iframe in the first place.

    The downside is that you've got to finish up what you're doing not in the iframe before doing anything in the iframe, so you can't go back and forth too easily.

    It might not work for your use case, but if/when it does, it's the easiest workaround I've found.

提交回复
热议问题