cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.66k stars 3.16k forks source link

type('{enter}') doesn't work when only 1 input blocking implicit submission #4495

Closed aisingoro closed 5 years ago

aisingoro commented 5 years ago

Current behavior:

I've already tried:

cy.get('input').eq(0).type('{enter}')

But it doesn't work. I've also tried:

cy.get('input').eq(0).type('{enter}').trigger('input')

And:

cy.get('input').eq(0).type('{enter}').trigger('input').eq(0).
{uparrow},{downarrow},tab()

they're all right.But ENTER isn't.

jennifer-shehane commented 5 years ago

Unfortunately we have to close this issue as there is not enough information to reproduce the problem. We have many tests that {enter} works, so we will need to know what is specific to your application that would make it not work here.

Please provide the HTML you are testing against, the error message that you are seeing, and a reproducible example that we can run locally and we will reopen the issue. 🙏

jodelasur commented 5 years ago

I'm also having this issue right now. I uploaded a sample system for you to check. See https://github.com/jodelasur/cypress-issue-4495.

The issue for me is that the submit is not firing. I'm assuming this is because of the 1st "other situation" listed in https://docs.cypress.io/api/commands/type.html#Form-Submission:

Does not submit a form if there are multiple inputs and no submit button.

However, looking at the spec referenced, https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission, it says (with emphasis added):

If the form has no submit button, then the implicit submission mechanism must do nothing if the form has more than one field that blocks implicit submission,

The form in the sample system has two inputs, one text and one hidden. It seems Cypress doesn't submit the form because there are multiple inputs. But per the spec, text input blocks implicit submission, but hidden doesn't. That means there's just one field that blocks implicit submission (not more than one), so the form should still submit.

I think my understanding of this is correct since browsers I've tested with (Chrome, Firefox) submits the form correctly. Also, when I add another text field to the form, that's the time when the browsers don't submit, conforming to the spec.

Hope this gets fixed.

jennifer-shehane commented 5 years ago

oh boy.

Yes, I believe your assessment is correct. Also, yes, the form does an implicit submission manually within your example.

I've simplified the HTML example for our testing purposes as shown below - this form should submit when typing {enter} in the input of type text.

<form>
  <input type="text">
  <input type="hidden">
</form>
Bigdragon13th commented 5 years ago

The spec is indeed very confusing 🤣

cypress-bot[bot] commented 5 years ago

The code for this is done in cypress-io/cypress#4574, but has yet to be released. We'll update this issue and reference the changelog when it's released.

cypress-bot[bot] commented 5 years ago

Released in 3.4.0.