0

As I am new to this UI automation/cypress world, need help to setting up the assertion on javascript object return by cypress-ag-grid package

My code is reading ag-grid data

cy.get("#myGrid").getAgGridData().should((data)=>{
cy.log(data)
})

Which is printing below object in console

[
{ id: 1, name: "tata", saftyRating: "50" },
{ id: 2, name: "maruti", saftyRating: "50" },
{ id: 3, name: "ford", saftyRating: "45" }
]

What all I want to iterate the safety rating value and put cypress assertion that value is greater than 50

1 Answers1

0

If you want to use cy.should(), you can simply iterate through the yielded data variable using JavaScript's array.forEach() function.

cy.get("#myGrid").getAgGridData().should((data)=>{
  data.forEach(({ saftyRating }) => {
    // using chai
    expect(+saftyRating).to.be.greaterThan(50);
    // using cypress
    cy.wrap(+saftyRating).should('be.gt', 50);
  })
});
agoff
  • 5,818
  • 1
  • 7
  • 20
  • I think we first need to covert the saftyRating value to number then only this assertion will work – Anil Tiwari Mar 22 '23 at 19:15
  • Ah good call out - missed that it was a string instead of a number. Updated! – agoff Mar 22 '23 at 19:30
  • can you please help me with this question as well https://stackoverflow.com/questions/75830614/how-to-chain-two-assertion-statment-in-or-form-in-cypress – Anil Tiwari Mar 24 '23 at 06:49