Add example of checking native HTML5 form validation message
See original GitHub issueI’m submitting a…
[ ] Bug report
[x] Content update
[ ] Process update (build, deployment, ... )
Type of bug / changes
Add an example of how to check that a form’s HTML form validation is shown when an input is invalid.
Maybe this should go in common assertions? https://docs.cypress.io/guides/references/assertions.html#Common-Assertions
Or our FAQ? I’m not sure.
it('check validation message on invalid input', () => {
cy.get('input:invalid').should('have.length', 0)
cy.get('[type="email"]').type('not_an_email')
cy.get('[type="submit"]').click()
cy.get('input:invalid').should('have.length', 1)
cy.get('[type="email"]').then(($input) => {
expect($input[0].validationMessage).to.eq('I expect an email!')
})
})
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Client-side form validation - Learn web development | MDN
The simplest HTML validation feature is the required attribute. To make an input mandatory, add this attribute to the element. When this ...
Read more >HTML5 Form Validation Examples < HTML - The Art of Web
HTML5 form input field attributes in combination with CSS allow you to provide instant feedback on the validity of form input text, including...
Read more >HTML5 form required attribute. Set custom validation message?
So I set the pattern attribute to check for numbers and optional decimals which gives the message, "Please match the requested format," on...
Read more >HTML5 Form Validation With the “pattern” Attribute - Web Design
The validation process evaluates whether the input value is in the correct format before submitting it. For example, if we have an input...
Read more >HTML5 Form Validation - Showing All Error Messages
2) In my example I start each error message with the contents of the field's <label> . This is because the messages for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, the example in the FAQ is misleading since it doesn’t show the required fields for the example. I’ll update it nonetheless.
Sorry for commenting on a closed issue. But I’m not sure if this is a bug or I have missed something? With the following setup:
A simple form
And the spec
I’m getting an AssertionError of AssertionError: Timed out retrying: Too many elements found. Found ‘1’, expected ‘0’.
If I however remove the
required
attribute from that input, it will pass. But shouldn’t that attribute should be there and when users click on the submit button without filling the field then the input will display a native error message?