Cypress mixes charCodes and keyCodes in `type()` function
See original GitHub issueCurrent behavior:
Reference to ASCII table: https://www.asciitable.com
Normall ASCII charcode of dot character .
is 46:
But cypress with type()
function uses charcode 190:
Using code bellow it doesn’t work too. Cypress just converts String.fromCharCode(46)
to 190
and normal .
is also 190
.
Code:
cy.get('#dateField').type('3' + String.fromCharCode(48) + String.fromCharCode(46) + '12.2020', {delay: 100});
What it does:
And here is our problem:
preventedDefault
Our JS verifies input and it preventDefault
by this RegExp: var regex = new RegExp("^[0-9.]+$");
.
(snippet of) JS:
date: function (event) {
if (event.charCode != 0) {
var regex = new RegExp("^[0-9.]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
}
}
Desired behavior:
Well… Cypress’ type()
function should use right charcodes.
Steps to reproduce:
I already posted these steps above.
Versions
Cypress ['3.0.1', '3.0.2']
on ['macOS 10.13', 'macOS 10.14', 'Windows 10 1803', 'Ubuntu 18.04']
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:11 (3 by maintainers)
Top Results From Across the Web
type - Cypress Documentation
type() may include any of the special character sequences below. These characters will pass along the correct keyCode , key , and which...
Read more >Cypress: type combination of keys and keyCodes
I need to navigate through the keyboard pressing ALT ...
Read more >Use createSyntheticEvent in Playwright Internal With Examples ...
Learn how to use createSyntheticEvent function in Playwright Internal framework for your next JavaScript automation project with LambdaTest Automation ...
Read more >Document Object Model (DOM) Level 3 Events Specification
This specification defines the Document Object Model Events Level 3, a generic platform- and language-neutral event system which allows ...
Read more >KeyboardEvent.charCode - Web APIs | MDN
A number that represents the Unicode value of the character key that was pressed. Examples. HTML. <p>Type anything ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A workaround that fixed it for me was just to delete the key mapping from the cypress internals in the beforeEach method:
This might break other stuff though…
Wow, well done cypress team! I literally just hit this issue and apparently it’s just been fixed! 👏