本文介绍了如何获取显示在表< td>中的数据在Cypress.io测试中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cypress.io测试中,在应用过滤器后检查表中显示的数据时,它抛出 CypressError:超时重试:无法读取未定义的属性eq。有人可以在下面的测试中建议如何解决问题吗?下表添加了HTML图片。

In a Cypress.io test, while checking for the 'data' displayed in a table after applying the filter, it throws "CypressError: Timed out retrying: Cannot read property 'eq' of undefined". Can someone please advise how to fix the problem in below test? Table HTML image added below.

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()函数是最简单的:

There are multiple ways to do this, but the contains() function is by far the simplest in this case:

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

这将获得元素并进行断言它包含一个 td 标记和文本 jacobs

This will get the table element and assert that it contains a td tag with the text jacobs.

值得注意的是, contains()也可以充当选择器,并且您可以按照赛普拉斯的典型方式继续链接它,就像这样:

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...

这篇关于如何获取显示在表< td>中的数据在Cypress.io测试中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 04:59