我正在尝试对需要上传用户的应用程序运行一些测试。我们使用 usecsv 来处理页面 iframe 中上传的文档。当尝试使用多种不同的方法来对其进行测试时,我不断遇到 cypress 错误:
Timed out retrying after 4000ms: cy.its() errored because the property: 0.contentDocument does not exist on your subject.
我尝试与不同的网站进行比较,看看我的命令是否正确:
`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);
});
});`
<iframe id="the-kitchen-table" title="The Kitchen - Table" width="800" height="800" src="/ingredients/table"></iframe>
按预期工作。
针对我的应用程序运行类似的操作时:
`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);
});
})`
<iframe src="https://app.usecsv.com/importer"></iframe>
在这种情况下,我收到上述错误。当只是尝试 cy.get('iframe[src="https://app.usecsv.com/importer"]') 时没有错误,所以我假设它确实找到了 iframe,但没有找到文档。尝试了其他帖子中的许多解决方案,但似乎没有一个对我有用。有什么想法吗?
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(...)
})
如果这没有帮助,请尝试递归方法,例如此处给出的
Cypress 12.8.1 无法与 Stripe Elements iframe 配合使用