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 to make sure the order of the buttons are same using cypress

I have a use case
I have three buttons Accept,Decline and Cookie Choices.
I click an option and after that when these buttons show-up,
I want to make sure the order of these buttons is exactly the same Accept,Decline and Cookie Choices
How do we automate this scenario in Cypress to make sure the order of these buttons is same.

>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

Select all the 3 buttons using. For example by placing a data-testid on them

<button data-testid="cookie-btn">Accept</button>
<button data-testid="cookie-btn">Decline</button>
<button data-testid="cookie-btn">Cookie choices</button>

then use first and next to go through them sequentially. For example

cy.get('[data-testid="cookie-btn"]')
  .should("have.length", 3)
  .first()
  .should("have.text", "Accept")
  .next()
  .should("have.text", "Decline")
  .next()
  .should("have.text", "Cookie choices");
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