我希望能够单击复选框,并测试元素不再在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。


当前回答

cy.get('[data-e2e="create-entity-field-relation-contact-name"]').should('not.exist');

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

.should('not.visible');

那样的话。

其他回答

使用.should('not.exist')来断言元素在DOM中不存在。


不要用not。可见的断言。它会错误地通过< 6.0,但现在正确地失败:

// for element that was removed from the DOM
// assertions below pass in < 6.0, but properly fail in 6.0+
.should('not.be.visible')
.should('not.contain', 'Text')

迁移文档:迁移到cypress -6-0

如果没有元素,我们可以使用简单的行:

cy。get (' [type = "复选框“]”)。should(“not exist。”)

柏树中没有试接流

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

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

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

在我的情况下,Cypress是如此之快,简单的。应该('not.be.visible')正在通过测试,之后,加载器出现和测试失败。

我成功地做到了:

cy.get('.loader__wrapper')
  .should('be.visible')
cy.get('.loader__wrapper', { timeout: 10000 })
  .should('not.be.visible')

当应用程序加载超过4秒时,最好将超时设置为10秒。