Reputation: 1354
I want to check if the text "You must enter a value"(Screenshot attached) is present in the login screen that I have created. This appears when a user touched the input field and then clicked on a different field or area without typing anything. So I tried to test it with cypress, but it says
".type() will not accept an empty string"
Cypress:
it('Should display You must enter a value if user does not type anything', () => {
cy.get('#username').type('')
cy.contains('You must enter a value')
})
I need help in fixing this, thank you.
Upvotes: 8
Views: 5259
Reputation: 79
cy.get(#id).type('{backspace}')
This will handle the error and works as intended, it will pass a ""
value to type()
Upvotes: 2
Reputation: 3721
Just focus and blur indeed:
it('Should display You must enter a value if user does not type anything', () => {
cy.get('#username')
.focus()
.blur()
cy.contains('You must enter a value')
})
Upvotes: 4