【发布时间】:2022-10-02 12:24:10
【问题描述】:
我尝试进行 E2E 测试柏.我必须访问表格中的多个链接并在访问页面后做出断言。
在赛普拉斯 UI 中,我看到页面已加载,如果我检查我可以看到 DOM 中的元素。但我的赛普拉斯断言不起作用,它说:
Timed out retrying after 4000ms: cy.should() failed because this element is detached from the DOM.
<div id=\"content\" class=\"css-1ddoub\">...</div>
Cypress requires elements be attached in the DOM to interact with them.
The previous command that ran was:
> cy.wait()
This DOM element likely became detached somewhere between the previous and current command.
我的测试代码:
cy.get(\'[id=\"content\"\').parent().within(()=>{
cy.get(\'[data-cy=\"list-item\"]\').each(item => {
const link = item.find(\'a\').first();
cy.visit(link.attr(\'href\')!)
cy.wait(5000)
cy.findByText(/report herunterladen/i)
})
})
有趣的是,如果我对 url 进行硬编码而不使用 .each,那么所有断言在 .visit() 之后都可以正常工作。
cy.visit(\'/de/banks/compare/?a=calculations.average&b=ins.PL.PKO\') // Hardcoded url
cy.wait(1000)
cy.findByText(/report herunterladen/i)
我尝试使用 cy.wait() 即使是像 30000 这样的大数字,但它没有用。
对我来说,赛普拉斯的 .each() 方法似乎存在错误。它不想在每个函数中加载页面 DOM 元素。
赛普拉斯:10.7.0
标签: html testing cypress e2e-testing cypress-testing-library