赛普拉斯 Iframe 找不到 0.contentDocument

0 iframe cypress

我正在尝试对需要上传用户的应用程序运行一些测试。我们使用 usecsv 来处理页面上 iframe 中上传的文档。当尝试使用多种不同的方法来对其进行测试时,我不断遇到 cypress 错误:

4000 毫秒后超时重试:cy.its() 出错,因为该属性:0.contentDocument您的主题上不存在。

我尝试与不同的网站进行比较,看看我的命令是否正确:

describe("iFrame", () => {
 
    beforeEach(() => {
      cy.visit('https://kitchen.applitools.com/ingredients/iframe');
    });
   
    it('should find a table in the iframe', () => {
      cy.get('iframe[src="/ingredients/table"]')
        .its('0.contentDocument').its('body').then(cy.wrap);
    });
  });`
Run Code Online (Sandbox Code Playgroud)
<iframe id="the-kitchen-table" title="The Kitchen - Table" 
  width="800" height="800" 
  src="/ingredients/table">
</iframe>
Run Code Online (Sandbox Code Playgroud)

其按预期工作。

针对我的应用程序运行类似的操作时:

describe("Sets up benefits, edits them and verifies functionality", () => {
    it("Changes employee start date for gratuity calculations", () => {
      cy.visit("/");

...
      cy.get('iframe[src="https://app.usecsv.com/importer"]')  
        .its('0.contentDocument').its('body').then(cy.wrap);
    });
})
Run Code Online (Sandbox Code Playgroud)
<iframe src="https://app.usecsv.com/importer"></iframe>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我收到上述错误。当只是尝试时cy.get('iframe[src="https://app.usecsv.com/importer"]')没有错误,所以我假设它确实找到了 iframe,但没有找到文档。尝试了其他帖子中的许多解决方案,但似乎没有一个对我有用。有任何想法吗?

小智 6

https://kitchen.applitools.com使用仅加载 HTML 的静态页面。一些 iframe 运行 javascript,这会重置contentDocument.

我建议首先尝试cypress-iframe

cy.enter('iframe[src="https://app.usecsv.com/importer"]').then(getBody => {
  getBody().find(...)
  getBody().contains(...)
})
Run Code Online (Sandbox Code Playgroud)

如果这没有帮助,请尝试递归方法,例如此处给出的
Cypress 12.8.1 不适用于 Stripe Elements iframe