可以说我有一个包含一些值的表。要从特定单元格中获取值,我可以使用此代码检查它是否包含一些文本:
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)
})
但它不起作用。
最佳答案
您可以执行以下操作:
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)
})
关于javascript - Cypress 如何获取文本长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65669034/