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

.type() does not enter a - or + after a valid number in an input of type number #6150

Closed
pkell opened this issue Jan 13, 2020 · 8 comments
Closed
Labels
E2E Issue related to end-to-end testing good first issue Good for newcomers stale no activity on this issue for a long period type: regression A bug that didn't appear until a specific Cy version release v3.7.0 🐛 Issue present since 3.7.0

Comments

@pkell
Copy link

pkell commented Jan 13, 2020

Current behavior:

Similar to to now closed 6055, if I try to type 123- into an input of type number, the field only contains 123. This is a bit of an edge case, we use these valid characters to make an invalid number to test field validation messages for our NumberTextField component.

This behavior is a discrepancy between Cypress and manual in Chrome as strings like 123- and 1+1 can be entered manually. Our tests are passing in 3.7 but failing in 3.8.2

Desired behavior:

.type() allows valid characters to be added to an input of type number even if the positioning of the characters makes the end value invalid.

Steps to reproduce:

use .type('123-') on an input of type number.
use .type('1+1') on an input of type number.

Versions

Chrome 79, Windows 10, Cypress 8.3.2

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Jan 13, 2020

I was actually never really able to get the assertion to pass in any version, but the behavior of typing is definitely different from 3.7.0.

index.html

<html>
<body>
  <input type='number'>
</body>
</html>

spec.js

it('type 123-', () => {
  cy.visit('index.html')
  cy.get('input').type('123-').should('have.value', '123-')
})

it('type 1+1', () => {
  cy.visit('index.html')
  cy.get('input').type('1+1').should('have.value', '1+1')
})

3.4.1

3.7.0

3.8.2

Manual typing

@jennifer-shehane jennifer-shehane added the type: regression A bug that didn't appear until a specific Cy version release label Jan 13, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jan 13, 2020
@jennifer-shehane jennifer-shehane added the good first issue Good for newcomers label Jan 13, 2020
@avallete
Copy link
Contributor

Yeah, into my fix #6055 I've already thought of some corner cases like this one.

Since I didn't found a satisfying solution, I've only resolved the actual issue and didn't pushed fix futher more.

I would like to share here some of my though:

First, some code lines to look at:
https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/keyboard.ts#L65
https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/keyboard.ts#L262

Basically, Cypress do validation on the typed data regarding of the input type.
Why do they do that ? Well, to set the value, Cypess .type change the javascript .value property of the element. So let's try it with the chrome console.

Here is what happen with your examples:

Screenshot from 2020-01-16 01-24-37

We see two things:

  1. The browser throw us a warning.
  2. The value isn't set inside the input html element (see: HTML Standard <input=number>)

Also, if you manually enter the value "123-" or "1+1" and then try to get the .value property of your <input> element, you'll will get an empty string as a result.

So, we are kind of stuck between the rock and a hard place here.

And I don't see any "really" satisfying solution. Because:

  1. Using the actual way Cypress .type set the value inside the element will not allow us to set this kind of value (even if no filter was applied on cypress side).
  2. The tests cases that @jennifer-shehane provided will fail anyway. Because even if the 'real' input is typed, according to the HTML Standard <input=number> there is no way for the rest of the javascript test to get this value out of the field (the only retrievable value is the sanitized one and must be a valid number).

I would really like to hear any suggestion about that topic.

@jennifer-shehane jennifer-shehane added v3.7.0 🐛 Issue present since 3.7.0 and removed priority: low 🎗 labels Jul 1, 2020
@jennifer-shehane
Copy link
Member

This is still an issue in 4.10.0.

@devtayls
Copy link

@jennifer-shehane, Has the community decided on this? I'd be happy to make the behavior match the OP. That is, allowing .type() to set the value on to things that are prohibited by standard.

This of course would break what @bkucera wrote regarding the standards and will throw browser console errors.

My vote would weigh in on allowing the behavior, if there isn't an overriding design value of the project. My reasoning is that since the behavior is available when manipulating the DOM (programmatically or manually) it may actually be a state that end users need to test. The fact that the state can exist and someone is asking to test it is pretty solid to me.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Apr 26, 2021

Probably the real-events plugin does this correctly. I haven't tried though. https://github.com/dmtrKovalenko/cypress-real-events

But in the end we need to implement something closer to that plugin instead of simulating the type.

@mschile mschile removed the triage label Aug 18, 2022
@nagash77 nagash77 added E2E Issue related to end-to-end testing and removed E2E-core labels Nov 8, 2022
@Hellsfoul
Copy link

Sorry to bring that up again.
Same here. I have to automate testcases, with invalid inputs.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Apr 2, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing good first issue Good for newcomers stale no activity on this issue for a long period type: regression A bug that didn't appear until a specific Cy version release v3.7.0 🐛 Issue present since 3.7.0
Projects
None yet
Development

No branches or pull requests