I am trying to learn cypress and am using the example.cypress.io site.
I want to check that when the ‘click to toggle popover’ button is clicked, cypress can see this.
So far i’ve tried:
it('clicks', () => { cy.get('.action-btn').click().should('have.value', true)
and
it('clicks', () => { cy.get('.action-btn').click next.should('This popover shows up on click').should('exist')// Assert that the pop-up exist
I’ve also tried to use the selector popover966184 to assert if it exists but nothing seems to work.
I’m very new to cypress, can someone help me?
2
Answers
The first part, you doing right, which is
cy.get('.action-btn').click()
, you need then to check if the popup with theid
equal topopover966184
exist.If you right-click and inspect in dev-tools before clicking, you will see the button HTML
If you click the button with dev-tools still open, you can see an attribute added
So, you could test that with
but the number part of the value would seem to change per test run.
Instead, you could specify only what is invariant every time you run the test,
aria-describedby
attribute is addedpopover
Asserting the popup is visible
That’s slightly different, there is an addtional element added below the button (see it in devtools).