我希望能够单击复选框,并测试元素不再在Cypress的DOM中。有人能建议你怎么做吗?

// This is the Test when the checkbox 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。


当前回答

您也可以使用下面的代码

expect(opportunitynametext.include("Addon")).to.be.false

or

should('be.not.be.visible')

or

should('have.attr','minlength','2')

其他回答

好吧,这似乎工作,所以它告诉我,我有更多的学习。应该()

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

你也可以搜索一个不应该存在的文本:

cy.contains('test_invite_member@gmail.com').should('not.exist')

这里是Cypress: 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]')

柏树中没有试接流

在java-selenium中,我们通常添加NoSuchElementException并执行case。如果UI没有显示某些基于角色的访问情况下的元素。

你也可以在元素体或元素的父容器内查询匹配的元素,然后对其长度做一些断言:

cy.get("body").find(".check-box-sub-text").should("have.length", 0);