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

前端 未结 5 1991
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条回答
  •  Happy的楠姐
    2020-12-29 19:52

    From the cypress API docs .should() section, using an arrow function:

    cy.get('.datatable').find('tr').should(($listOfElements) => {
       expect($listOfElements).to.have.length(4)
       // any other assertions, for example the below one
       // expect($listOfElements).to.have.any.keys('key1', 'key2')
    })
    

    This approach will allow you to use Chai BDD notation and assert more than one thing on your list of elements.

提交回复
热议问题