2

In my e2e, I need to check if the datatable is populated first before before checkboxes in the table are clicked.

I am able to check the count like so

cy.get('.p-datatable-table').find('tr').its('length').should('be.gte', 0);

unfortunately, the below does not work.

  if (cy.get('.p-datatable-table').find('tr').its('length').should('be.gte', 0)) {
    cy.get('.select-all-boxes').click();
  }

Any suggestions?

1
  • In Cypress, commands do not return their subjects, instead yield them.
    – Atul KS
    Commented Feb 5, 2023 at 6:08

1 Answer 1

4

You can't use the expression cy.get('.p-datatable-table').find('tr').its('length').should('be.gte', 0) to perform an if check.

The result of that expression is a chainable, so you have to chain it

cy.get('.p-datatable-table').find('tr').its('length')
  .then(length => {
    if ( length ) {
      cy.get('.select-all-boxes').click()
    }
  })

Not sure what you expect with .should('be.gte', 0) but it does nothing so I dropped it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.