Cypress: `.type()` does not type chars in number input beyond special chars (like `,`)

Created on 18 Dec 2019  路  7Comments  路  Source: cypress-io/cypress

Current behavior:

Pre-conditions - in my text form "," sign not allowed to input

Input inside type() func:

1,99

Output:

1

Desired behavior:

199

It worked in previous version of cypress correctly and problem I met in 3.8.0

Steps to reproduce: (app code and test code)

Just try to type from tests some signs that couldn't be written.

Versions

Cypress 3.8.0
OS: Mac Mojave
Browser: Chrome

pkdriver cy.type 鈱笍 regression v3.8.0

All 7 comments

What is the type of your input? We've also noticed some difference in recent versions and tracked it down to these regexp: https://github.com/cypress-io/cypress/blob/6ed8d31cf045acd486757474934ef84f5f96cb74/packages/driver/src/cy/keyboard.ts#L65

To be honest I don't think that automation framework should do this at all.

This is only for number inputs, and Cypress has to do this because they replicate certain browser / html functionality, unlike Selenium.
But I agree, something went really quite wrong with the number input in 3.8.0.

What is the type of your input? We've also noticed some difference in recent versions and tracked it down to these regexp:

I'm using them as string obj. Should I prefer to use them as a number type or it doesn't matter?

@abaybabaydabudidabuday Can you paste in the html of the input element? We want to know the type attribute. Should look something like:

<input type="???" />

I verified this behavior in 3.8.0.

When typing manually, I can type 1 , 0 0 0 where the , does not display in the input, but the entire 1000 is set as the value.

index.html

<!DOCTYPE html>
<html>
<body>
  <input type="number"/>
</body>
</html>
it('Type in number', () => {
  cy.visit('index.html')
  cy.get('input').type('1,000')
})

3.7.0

Screen Shot 2019-12-19 at 2 57 47 PM

Events table when clicking on 'type' command

Screen Shot 2019-12-19 at 2 59 53 PM

3.8.0

You can see the test run where it only has 1 in the value.

Screen Shot 2019-12-19 at 2 56 30 PM

Events table when clicking on 'type' command. Seems like the input event is never firing for the , + 0 characters.

Screen Shot 2019-12-19 at 2 53 24 PM

Workaround

Roll back to 3.7.0 in the meantime.

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

Released in 3.8.1.

Was this page helpful?
0 / 5 - 0 ratings