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

cy.type() adhere to maxlength on text input #928

Closed
JosiahRooney opened this issue Nov 17, 2017 · 11 comments
Closed

cy.type() adhere to maxlength on text input #928

JosiahRooney opened this issue Nov 17, 2017 · 11 comments
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: bug
Milestone

Comments

@JosiahRooney
Copy link
Contributor

Is this a Feature or Bug?

Feature

Current behavior:

cy.type ignores maxlength attribute on an input element.

Desired behavior:

cy.type() should not ignore maxlength attribute on an input. After .type() reaches the maxlength, it should ignore the rest of the input string.

How to reproduce:

Use cy.type() on a text input with a maxlength attribute, passing a string to .type() that is longer than the maxlength.

@jennifer-shehane
Copy link
Member

Can confirm - is a bug in v1.0.3. On typing over maxlength, the input displays more than maxlength and the assertions fail, returning the value beyond the allowed maxlength.

HTML

<input type="text" class="wait-input1" maxlength="5">

Test code

it('Type over maxlength', function(){
  cy.visit('http://localhost:8080/commands/waiting')
  cy.get('.wait-input1').type('123456789')
    .should('have.value', '12345')
    .and('not.have.value', '123456789')

Result in Cypress
screen shot 2017-11-18 at 9 57 25 am

For solution, PRs welcome

@jennifer-shehane jennifer-shehane added good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory stage: ready for work The issue is reproducible and in scope type: bug labels Nov 18, 2017
@JosiahRooney
Copy link
Contributor Author

I'd love to submit a PR here. This is the first time I have contributed to a project on github (outside of my own). I will carefully read the contributing.md doc and get started. Please let me know if there's anything outside of that doc that I should know. Thanks!

@jennifer-shehane
Copy link
Member

Awesome @JosiahRooney, feel free to open a WIP PR if you get stuck or have questions at all. 👍

@JosiahRooney
Copy link
Contributor Author

JosiahRooney commented Nov 18, 2017

I'm wondering if this would suffice (adding to line 115 of packages/driver/src/cy/commands/actions/type.coffee):

if options.$el.attr("maxlength") and chars.length > options.$el.attr("maxlength")
  chars = chars.slice(0, options.$el.attr("maxlength"))

@JosiahRooney
Copy link
Contributor Author

JosiahRooney commented Nov 18, 2017

I made a WIP PR here: #930 @jennifer-shehane

@JosiahRooney
Copy link
Contributor Author

@jennifer-shehane I think this is all finished up. Do I close the issue now or do you guys do that? Thanks

@brian-mann brian-mann added this to the 1.1.1 milestone Nov 21, 2017
@brian-mann
Copy link
Member

Fixed by #930

@brian-mann
Copy link
Member

Released in 1.1.1.

@RobertRiviera
Copy link

I'm very new to all this, but I just wanted to ask if someone could verify whether the fix that was included in 1.1.1 considers special character sequences like {selectall} and {backspace} when respecting the maxlength attribute.

@brian-mann
Copy link
Member

That's a good point. It likely does not. A quick test would confirm this.

@RobertRiviera
Copy link

I upgraded to 1.1.1 yesterday but had to roll back to 1.1.0 because several of my tests that used textboxes with a maxlength attribute started failing. The cy.clear() command was also affected for obvious reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
Development

No branches or pull requests

4 participants