0
let values = []
cy.visit(url)
cy.get('selector')
  .find('td')
  .each(($el, $index) => {
    cy.wrap($el)
      .invoke('text')
      .then(text => {
        if ($index!==0) {
          values.push(text.trim())
        }
      })
  })
 .then(() => expect(values).to.deep.eq.(["Value1", "Value2", "Value3", "Value4"])

I tried to print all values for example in the row the values are aaray[0] value1, aaray[1] value2, aaray[2] value3, aaray[3] value4. While executing above only the values 1, 2, 3 are displayed array[0] value is not showing, how to assert all the 4 values

Grainger
  • 146
  • 9

1 Answers1

1

You would get all the values if you removed the if().

cy.get('selector')
  .find('td')
  .each(($el, $index) => {
    cy.wrap($el).invoke('text')
      .then(text => 
        values.push(text.trim())
      })
  })
  .then(() => expect(values).to.deep.eq.(["Value1", "Value2", "Value3", "Value4"])
Grainger
  • 146
  • 9
  • After removing it displaying result as [4] equals to [4] instead I need all the four values needs to shown example [value1] equals to [value1] like that – sarath kumar Nov 17 '22 at 03:32