In Cypress how to count a selection of items and get the length?

前端 未结 5 1990
Happy的楠姐
Happy的楠姐 2020-12-29 19:15

I\'m starting to learn Cypress. I have a 4 row table (with a class of datatable). I can verify the number of rows this way:

cy.get(\'.datatable\').find(\'tr\         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-29 19:47

    One option is to use "have.length" ...

    cy.get('.datatable tr').should('have.length', 4)
    

    ...another option is to use should

    cy.get('.datatable tr').should(($tr) => {
        expect($tr).to.have.length(4)
    })
    

    ...or then (synchronous queries)

    cy.get('.datatable').then(($table) => {
      // synchronously query to find length of elements
      expect($table.find('td').length).to.equal(4)
    })
    

提交回复
热议问题