赛普拉斯如何获取文本长度

时间:2021-01-11 14:47:44

标签: javascript html cypress e2e-testing

假设我有包含一些值的表格。要从特定单元格中获取值,我可以使用此代码来检查它是否包含一些文本:

cy.get('table > tbody > tr:nth-child(1) > td:nth-child(1)', {timeout: 15000}).should('have.text', "Ketchup")

如何断言/检查该文本的最小长度是否为 5?

我尝试使用

cy.get('table > tbody > tr:nth-child(1) > td:nth-child(1)', {timeout: 15000}).its('text').should("have.length", 5)
    })

但它不起作用。

1 个答案:

答案 0 :(得分:3)

您可以执行以下操作:

cy.get('table > tbody > tr:nth-child(1) > td:nth-child(1)', {
    timeout: 15000
}).invoke('text').then((text) => {
    expect(text.length).to.be.at.least(5)
})