如何在 table <td> in Cypress.io 测试中显示数据?

How to get data displaying in a table <td> in Cypress.io test?

在 Cypress.io 测试中,在应用过滤器后检查 table 中显示的 'data' 时,它会抛出 "CypressError: Timed out retrying: Cannot read property 'eq' of undefined"。有人可以建议如何解决以下测试中的问题吗? Table HTML 下面添加了图片。

describe('Filter Test', function() {
    it.only('Check if the records are filtered successfully', function() {
        cy.visit('http://www.seleniumeasy.com/test/table-search-filter-demo.html')          
        cy.get('button').contains('Filter').click()
        cy.get('input[placeholder="Username"]').type('jacobs')  
        cy.get('table').should(($tr) => {
        const $tds = $tr.find('td') // find all the tds
        expect($tds.cells.eq(0)).to.contain('jacobs')   
        })

    })      

})

有多种方法可以做到这一点,但 contains() 函数在这种情况下是迄今为止最简单的:

cy.get('table').contains('td', 'jacobs');

这将获取 table 元素并断言它包含带有文本 jacobs.

td 标签

It's worth noting that contains() also acts as a selector, and in typical Cypress fashion you can continue chaining off it, like so:

cy.get('table').contains('td', 'jacobs').should('be.visible');

cy.get('table').contains('td', 'jacobs').then(elem => {
    // Do something with this specific element...
});

// etc...