cypress-io / cypress

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

Cypress does not type commas into number inputs #30411

Open Natrocx opened 1 month ago

Natrocx commented 1 month ago

Current behavior

Currently cypress actively prevents typing commas into inputs of the type "number". As this is the decimal separator in some languages/locales like German, this prevents accurate testing in the way a user might interact with the page. There is a regex which prevents such inputs: https://github.com/cypress-io/cypress/blob/0e316966af3f281b3e297cae2d5f4c0c3054f8ed/packages/driver/src/cy/keyboard.ts#L71

Desired behavior

As far as I am aware, there is no reason to prevent a comma from being typed into a number input. Indeed the HTML specification itself suggests that the "user agent"/browser should allow such inputs and convert them internally (which is indeed what Chrome does in my case when I manually type into the inputs) https://html.spec.whatwg.org/multipage/input.html#number-state-(type=number). I am unsure about how much of the browser's validation can actually be used in this case since the implementation does not always simulate key presses, and the implementation details of converting the number input's values differs between browsers but there should be a way to type the characters mentioned in the spec regardless of their validity in the context of a en-US locale input (maybe with force: true if there is no other way).

Test code to reproduce

There is no need to reproduce this as the issue is not unexpected behaviour.

Cypress Version

v13.15.0

Node version

v22.7.0

Operating System

Any

Debug Logs

No response

Other

Someone familiar with the implementation should consider whether it is safe to remove or extend (with commas etc.) the validation regex in every case and either do so or add a way to ignore the regex.

nsbarsukov commented 1 month ago
Natrocx commented 1 month ago

Also this issue from 2020 describes the bug: https://github.com/cypress-io/cypress/issues/7775

Natrocx commented 1 month ago

Maybe @kuceb would like to comment on why this regex is necessary. As far as I understand, it should not cause problems to just emit events for invalid keys when using simulated key events since it is the browsers job to filter these out on submission or when receiving the key events.

I further don't understand what this line is supposed to do: https://github.com/cypress-io/cypress/blob/c420d9c6f9c99560bd826017b3961bb176a1a4d2/packages/driver/src/cy/keyboard.ts#L735 It appears the simulated property of the typeoptions is set but never read from. Maybe this is the legacy of an older typing mechanism?