확인란을 클릭하고 Cypress의 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에 없어야합니다.
답변
잘 작동하는 것 같습니다. 따라서 .should ()에 대해 더 배울 점이 있습니다.
cy.get('.check-box-sub-text').should('not.exist');
답변
존재하지 않는 텍스트를 검색 할 수도 있습니다.
cy.contains('test_invite_member@gmail.com').should('not.exist')
Cypress의 결과는 다음과 같습니다. 0 matched elements
답변
cy.get('[data-e2e="create-entity-field-relation-contact-name"]').should('not.exist');
일부 오류 메시지가 숨겨져 잘못된 결과가 발생할 수 있습니다. 사용하는 것이 좋습니다
.should('not.visible');
이 경우에.
답변
나를 위해 일한 것은 다음과 같습니다.
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]')
답변
https://docs.cypress.io/guides/references/assertions.html#Existence 에 따르면
// retry until loading spinner no longer exists
cy.get('#loading').should('not.exist')
이것은 제거되는 경우에 효과적입니다. 하지만 절대 존재하지 않으려는 경우 … docs.cypress.io/guides/references/assertions.html#Existence 사라질 때까지 다시 시도합니다. 이것은 대부분의 사람들이 찾게 될 제목 문제에는 실제로 효과가 없습니다.
그러나 우리의 경우에는 결코 존재하지 않는지 테스트하고 싶다면.
// 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`);
});
})
답변
아래 코드를 사용할 수도 있습니다
expect(opportunitynametext.include("Addon")).to.be.false
또는
should('be.not.be.visible')
또는
should('have.attr','minlength','2')
답변
