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

Update/improve cy.type validation logic #586

Closed
chrisbreiding opened this issue Aug 9, 2017 · 10 comments · Fixed by #2016
Closed

Update/improve cy.type validation logic #586

chrisbreiding opened this issue Aug 9, 2017 · 10 comments · Fixed by #2016
Assignees
Labels
pkg/driver This is due to an issue in the packages/driver directory type: enhancement Requested enhancement of existing feature
Milestone

Comments

@chrisbreiding
Copy link
Contributor

It appears fairly common that users need to type into an input that has an invalid type attribute (type="STRING", type="username"), triggering the error cy.type() can only be called on textarea or :text.

Here are two possible ways to improve the experience for this use case:

  1. Allow validation to be bypassed with either { force: true} or { validation: false }. Also, improve the error message so it's clear what :text means and include details on how to bypass validation.

  2. Instead of whitelisting input types, blacklist certain types instead (e.g. checkbox). This would provide a good error message if typing into something that's blacklisted, but allow users to type into inputs with types that aren't accounted for, just as a browser actually allows.

@noah-potter
Copy link

Having a { force: true } option would be great for our use case. We have a div listening for keyboard shortcuts such as ctrl + b, ctrl + m, etc. These are used to access power-user/admin windows. We're able to work around the issue by attaching these to the body, but ideally we would be able to force cypress to type into any element.

@jennifer-shehane
Copy link
Member

@anocaj
Copy link

anocaj commented Apr 5, 2018

Is this something that will be added? We are struggling to make cypress type into a paragraph that is inside a content editable div.

cy.type() can only be called on textarea or :text. Your subject is a: <p>...</p>

@patrickdorn
Copy link

Is there any kind of "workaround" or "dirty hack" available to bypass this issue until this is solved?

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope type: enhancement Requested enhancement of existing feature good first issue Good for newcomers labels Apr 11, 2018
@Magneticmagnum
Copy link

My company is also exploring Cypress and wondering if this will be a feature that will be supported by the Cypress team in the future?

Our use case is similar to anocaj; We want to simulate typing into a complex text editor that is a div.

@jennifer-shehane
Copy link
Member

Yes, we do intend this to be done in the future, but currently it is not assigned to anyone. The code can be found here if anyone wants to begin a Work in Progress PR: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/actions/type.coffee#L23

@kuceb
Copy link
Contributor

kuceb commented Jun 21, 2018

@Magneticmagnum that is not addressed by this issue...however we should already support typing into divs with attribute contenteditable .

@kuceb
Copy link
Contributor

kuceb commented Jul 12, 2018

This will be fixed by an upcoming patch release. It's really as simple us using the type property instead of type attribute.
The type property of <input type="asdf"> is "text"

So we can still whitelist input types, as long as we use the type property getter

@jennifer-shehane jennifer-shehane added stage: in progress and removed stage: ready for work The issue is reproducible and in scope labels Jul 12, 2018
@kuceb kuceb added this to the 3.0.3 milestone Jul 16, 2018
brian-mann pushed a commit that referenced this issue Jul 23, 2018
this grew to a large PR fixing many cy.type issues.

fix #365
fix #420
fix #586 
fix #593 
fix #596 
fix #610 
fix #651
fix #940
fix #1002 
fix #1108
fix #1171
fix #1209 
fix #1234 
fix #1366
fix #1381 
fix #1684 
fix #1686
fix #1926 
fix #2056
fix #2096 
fix #2110 
fix #2173
fix #2187
@jennifer-shehane jennifer-shehane removed stage: needs review The PR code is done & tested, needs review stage: needs investigating Someone from Cypress needs to look at this stage: in progress labels Jul 23, 2018
@wasiqkhan786
Copy link

nothing is working with cy.type when subject is not typeable.please create some solution.

@jennifer-shehane
Copy link
Member

@wasiqkhan786 This issue has been resolved and there are tests against it. This issue will be closed to further comment.

If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Aug 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg/driver This is due to an issue in the packages/driver directory type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants