Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Lets say I have table which consist of some values. To get the value from specific cell I can use this code to check whether it contains some text:

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

How can I assert/check if that text has minimum length of 5?

I tried using

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

But it does not work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
274 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do something like:

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)
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...