赛普拉斯:测试元素是否不存在

问题描述 投票:45回答:2

我希望能够单击一个复选框并测试一个元素不再位于赛普拉斯的DOM中。有人可以建议你怎么做吗?

//This is the Test when the check box is clicked and the element is there
cy.get('[type="checkbox"]').click();
cy.get('.check-box-sub-text').contains('Some text in this div.')

我想做与上述测试相反的事情。所以当我再次点击它时,带有类的div不应该在DOM中。

cypress
2个回答
68
投票

好吧这似乎有用,所以它告诉我我还有更多要了解的内容.should()

cy.get('.check-box-sub-text').should('not.exist');

4
投票
cy.get(data-e2e="create-entity-field-relation-contact-name").should('not.exist')

可能会导致一些错误的结果,因为一些错误消息会被隐藏。它可能更好用

.should('not.visible') 

在这种情况下。


0
投票

这对我有用:

cy.get('[data-cy=parent]').should('not.have.descendants', 'img')

我检查一些<div data-cy="parent">里面没有图像。关于原始问题,您可以在内部节点上设置data-cy="something, i.e. child"属性并使用此断言:

cy.get('[data-cy=parent]').should('not.have.descendants', '[data-cy=child]')
© www.soinside.com 2019 - 2024. All rights reserved.