Cypress: Test if element does not exist

前端 未结 7 2142
一个人的身影
一个人的身影 2020-12-09 14:42

I want to be able to click on a check box and test that an element is no longer in the DOM in Cypress. Can someone suggest how you do it?

//This is the Test          


        
相关标签:
7条回答
  • 2020-12-09 15:07

    According to https://docs.cypress.io/guides/references/assertions.html#Existence

    // retry until loading spinner no longer exists
    cy.get('#loading').should('not.exist')
    

    This works for the case that it is being removed. but in the case that you want it to never exist... docs.cypress.io/guides/references/assertions.html#Existence It will retry until it goes away. This doesn't really work for the title problem which is what most people will be looking for.

    However if you want to test that the thing never exists in our case.

    // Goes through all the like elements, and says this object doesn't exist ever
    cy.get(`img[src]`)
            .then(($imageSection) => {
                $imageSection.map((x, i) => {
                    expect($imageSection[x].getAttribute('src')).to.not.equal(`${Cypress.config().baseUrl}/assets/images/imageName.jpg`);
                });
            })
    
    0 讨论(0)
提交回复
热议问题