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 assert list with fixtures list in Cypress

I have Toolbar.json in fixtures directory. In that json file I have a list

{
"toolbar_elements": [

    "Contact",
    "Language",
    "About",
    "Privacy"
]

}

And I have a website with main menu which has these 4 elements.

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

<div class="mainMenu">
  <ul>
     <li>
       <a>Contact</a>
     </li>
     <li>
       <a>Language</a>
     </li>
     <li>
       <a>About</a>
     </li>
     <li>
       <a>Privacy</a>
     </li>
   </ul>
 </div>

I want to make assertion and don’t know how.

cy.get('[class="mainMenu"]').find('li').should('have.length', 4)

This passes. How can I check if list in Toolbar.json is the same as this in mainMenu?

Thank you

>Solution :

You can do something like this:

cy.fixture('Toolbar.json').then((toolbar) => {
  cy.get('.mainMenu ul li a').each(($ele, index) => {
    expect(toolbar.toolbar_elements[index]).to.equal($ele.text().trim())
  })
})
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