我不确定我是否了解完整情况,但良好的技能检查Cypress.dom.isVisible($0)
.
您可以在测试中使用完全相同的表达式:.should()
带回调
cy.get('.price-total')
.should($priceEl => { // retries if necessary when expect fails
expect(Cypress.dom.isVisible($priceEl).to.eq(true)
})
我不确定这是确定的,见过一个 Angular 应用程序(选择控件),其中父级在display: none
但孩子对用户可见(参考访问父级隐藏的元素 https://stackoverflow.com/a/47625195/14783414)
在这个答案中,自定义函数用于重新定义可见性标准。诀窍是弄清楚要检查您的应用程序的内容......
// Change this function if other criteria are required.
const isVisible = (elem) => !!(
elem.offsetWidth ||
elem.offsetHeight ||
elem.getClientRects().length
)
在父元素删除之前,您可能只是有一个延迟(例如动画)display: none
.
在控制台中检查父级,看看它最终是否有不同的display
value.
在这种情况下,首先检查parent(不是曼努埃尔所说的孩子)。
cy.get('td.item-total')
.should('not.have.css', 'display', 'none')
.find('.price-total')
.should($priceEl => {
expect(Cypress.dom.isVisible($priceEl).to.eq(true)
})