带有 Cypress 的 iframe:如何在 iframe 内等待 api 调用

Nbe*_*laf 6 iframe cypress

我正在使用 Cypress 来测试 iFrame 中的行为

对服务器端的请求是在 iFrame 内部完成的,
我的测试应该等待请求完成并继续测试

目前我正在等待 api 调用通过以下方式完成:

 cy.route("POST", "URL")).as("Alias");
 cy.wait("@Alias");
Run Code Online (Sandbox Code Playgroud)

Api 被成功调用,但在 Cypress 中它因等待调用 API 超时而失败。

Jbo*_*cly 1

我有同样的略有不同的问题。我建议您在 iframe 中输入这段代码,您将根据您的需要进行修改:

cy.get('iframe').then((iframe) => { const body = iframe.contents().find('body'); cy.wrap(body).find('a').click(); });

我在这里找到了解决方案

对于 API 等待问题,您可以使用 cy.wait()

cy.wait(time)

医生