Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of checking native HTML5 form validation message #1824

Closed
jennifer-shehane opened this issue Jun 28, 2019 · 11 comments · Fixed by #1919
Closed

Add example of checking native HTML5 form validation message #1824

jennifer-shehane opened this issue Jun 28, 2019 · 11 comments · Fixed by #1919

Comments

@jennifer-shehane
Copy link
Member

I'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!')
  })
})
@ryanpedersen42
Copy link
Contributor

Feeling like this might be best in FAQ because that Common Assertions section is really focused on using the assertions listed before with .should(). Maybe a new "How can I check that a form's HTML form validation is shown when an input is invalid?" is the right call?

@jennifer-shehane
Copy link
Member Author

@ryanpedersen42 Yah, I agree!

@ryanpedersen42
Copy link
Contributor

I'm on it!

jennifer-shehane pushed a commit that referenced this issue Aug 5, 2019
* Adding HTML form validation to FAQ, closes #1824 (#1919)

* update ja/cn docs to match develop changes

* parseSpecialCharSequences docs (#1886)

* Add file for 3.5.0 changelog

* Added documentation for disableSpecialCharSequences option for… (#1885)

* Added documentation for disableSpecialCharSequences option for cy.type

* update description of disableSpecialChar... to be more active voice


Co-authored-by: Jennifer Shehane <[email protected]>

* rename `disableSpecialChars` opions (#1903)

* Revert "Added documentation for disableSpecialCharSequences option for… (#1885)"

This reverts commit 298df85.

* rename disableSpecialCharSequences

* fix description of 'parseSpecial...' - was opposite meaning, still mentioned disable

- Add notes about how to disable special char sequences in more places
in type doc.

* Remove changelog so I can just commit new feature changes

* chore(deps): update dependency @types/jest to version 24.0.16 🌟 (#1920)



Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: Jennifer Shehane <[email protected]>

* Update continuous-integration.md (#1912)

* copy changes to ja/cn file

* Add elm-batteries project template to plugins (#1925)

* chore(deps): Update dependency to version 🌟 (#1929)



Co-authored-by: Renovate Bot <[email protected]>

* Add example of setting 'parseSpecialCharSequences' to false (#1927)

* update wait requirements to specify when it can be used as chil… (#1930)

- also alphabetize requirements methods

* Improve GitHub integration "run group" link target (#1924)

* Improve GitHub integration "run group" link target

* Update ja locale link

* Update zh-cn locale link

* Use internal link syntax

* chore(deps): update dependency husky to version 3.0.2 🌟 (#1922)



Co-authored-by: Renovate Bot <[email protected]>

* Remove deps that appear to be unused (mostly devDeps) (#1931)

* Clarify some of the options available in Module API (#1934)

* Add contentful based top banner (#1911)

* data fetch && swig && styles

* banners actualization script

* finish (?)

* finish (?)

* remove "extends" from eslint settings

* remove sensitive info

* update hexo index file

* banner padding fix

* remove Promise.protoype.finally() from hexo index script

* Contentful driven banners, parsed dynamically:
Hexo index.js && data fetch && swig && styles && banners_actualization script

* add cypress test for banners

* docs update v1

* Fix toc width so that it doesn't create a horizontal scrollbar on smaller heights screen.

* package-lock

* just a few tweaks to the README instructions

* fixed conflict issue from package.json merge

* add GitHub Enterprise integration support notice (#1936)

* add GitHub Enterprise integration support notice

* add japanese and chinese versions

* remove remove package that was accidentally installed

* Update banner tests to be more resilient to changes in content

- instead of regex removals, use utf8 encode the html content provided
- use Cypress commands instead of direct javascript - so we can have
better logs during CI runs and also have retryability.

* package-lock

* Handle html entities also

- Basically - we’re done parsing that HTML, what a mess. Only going to
parse the text within the HTML now for the tests.
- Add an html entity within the banners.yml so we make sure these are
tested.

* Add a catch handler to the contenful.getEntries - that will continue to run hexo.init if failed

* gitignore banners.yml??

* Header partial cache removal (#1937)



Co-authored-by: null <[email protected]>

* Fix issue with righthand toc slipping under header during test

* add cy.get by name attribute example (#1941)

* add cy.get by name attribute example

* copy to ja/cn


Co-authored-by: Jennifer Shehane <[email protected]>

* add robots.txt and copy it to public folder during build (#1942)

* add robots.txt and copy it to public folder during build

* add robots.txt test

* add custom methods on Cypress for checking env name

* switch another spec to use method

* Add hash scroll offset (#1945)

* temporary workaround for hash scroll

* Add tests to ensure the docs scroll properly when clicking on a toc link


Co-authored-by: null <[email protected]>
Co-authored-by: Jennifer Shehane <[email protected]>

* Add mobile header fix (#1949)

* temporary workaround for mobile header

* scroll container to top

* toc fix

* Add note for <-loopback> usage

* Update proxy-configuration.md
@konekoya
Copy link
Contributor

konekoya commented Jul 30, 2020

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

<form action="">
      <input type="text" id="name" name="name" required />
      <button type="submit">Submit</button>
</form>

And the spec

describe("Element", () => {
  before(() => {
    cy.visit("/");
  });

  it("it should have user value", () => {
    cy.get("input:invalid").should("have.length", 0);
  });
});

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?

@rathorevaibhav
Copy link

Getting the same error as @konekoya

Any help would be appreciated.

@jennifer-shehane
Copy link
Member Author

@konekoya @rathorevaibhav The test is failing as intended in your situation. The input is required, meaning it requires some value to be present in the input. With the test you've written, there is no value in the input, so the test fails since your test is testing that there are no invalid elements present.

If the input is empty, the test fails, as designed, since the input is required

Screen Shot 2021-01-11 at 11 00 13 AM

If you fill out the required input, the test passes

Screen Shot 2021-01-11 at 10 59 23 AM

The example in the FAQ is wrong basically, the assertions are backwards. I'll update the example.

@jennifer-shehane
Copy link
Member Author

Sorry, the example in the FAQ is misleading since it doesn't show the required fields for the example. I'll update it nonetheless.

@jennifer-shehane
Copy link
Member Author

Opened a PR here: #3480

@NimashaHatake
Copy link

Hi,
I want to know how to write a test for HTML5 built-in popup validation error in Cypress TypeScript.

This is the message I get when I click on the submit button:
Screenshot 2023-05-26 135811

I tried to add the below code, but then I got an error like this.
Screenshot 2023-05-26 135715

Email field code (inspect):
<input type="text" name="Email" id="UserEmail" class="form-control" placeholder="E-mail" required autofocus style="margin-bottom:14px;">

@MikeMcC399
Copy link
Contributor

@NimashaMySendle

Adding a comment to this closed issue, which was about adding an example to the documentation, is not the best place for your question.

For questions about how to use Cypress you can go to

Discord chat

and use the i-need-help channel.

If you believe that you have found a bug in Cypress, you can open a new issue in the main Cypress repository.

@NimashaHatake
Copy link

@NimashaMySendle

Adding a comment to this closed issue, which was about adding an example to the documentation, is not the best place for your question.

For questions about how to use Cypress you can go to

Discord chat
and use the i-need-help channel.

If you believe that you have found a bug in Cypress, you can open a new issue in the main Cypress repository.

I'm new to cypress automation. thank you so much for your response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants