Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How cy.click a subset of buttons

I’m testing multiple delete from a table, but to ensure that not all items are deleted by mistake I want to leave the first item. The selector is the same for every row, but I need to filter the selection after fetching. This code deletes all items, works but how do I test with 1 remaining?

cy.get('[data-cy="item"]').click({multiple: true })
cy.contains('button', 'Delete selected').click()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can slice the selected elements

cy.get('[data-cy="item"]')
  .invoke('slice', 1)             // exclude 1st row
  .click({multiple: true})

cy.contains('button', 'Delete selected').click()

cy.get('[data-cy="item"]')
  .its('length')
  .should('eq', 1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading