Cypress: Write in a input type = String

Created on 7 Jun 2017  路  2Comments  路  Source: cypress-io/cypress

  • Operating System: n/a
  • Cypress Version:0.19.2
  • Browser/Browser Version: Electron

Are you requesting a feature or reporting a bug?

Request a feature

Current behavior:

Error when type in a Input with type="STRING"

Expected behavior:

Write in a input type STRING instead of type text or textarea

How to reproduce the current behavior:

Test code:

Cypress code

cy.get('div#content > form > md-card > md-card-content > div:nth-child(4) > md-input-container > input').first().type('Recurso1')

HTML label

<input ng-model="properties[attribute.id]" name="0" id="0" min="" max="" ng-required="true" ng-if="isAdding" aria-label="atributo0001" class="ng-pristine ng-untouched ng-scope md-input ng-invalid ng-invalid-required" required="required" aria-required="true" aria-invalid="true" type="STRING">

Additional Info (images, notes, stack traces, etc)

Most helpful comment

Thanks for submitting an issue!

By default, I think it's best that Cypress validates that what's being typed into is a valid text input. However, we could make it so that passing {force: true} bypasses the validation, or have a {validate: false} option (that's true by default).

To get around this for now, you could set the value directly instead of using cy.type():

cy.get('input').then(($input) => {
  $input.val('text')
});

Or you could change the type of the input to 'text' before typing and change it back after. This is bit more verbose and might not work if your app relies on the type being STRING during the typing.

cy.get('input')
.then(($input) => {
  $input[0].type = 'text'
  return $input
});
.type('text')
.then(($input) => {
  $input[0].type = 'STRING'
});

All 2 comments

Thanks for submitting an issue!

By default, I think it's best that Cypress validates that what's being typed into is a valid text input. However, we could make it so that passing {force: true} bypasses the validation, or have a {validate: false} option (that's true by default).

To get around this for now, you could set the value directly instead of using cy.type():

cy.get('input').then(($input) => {
  $input.val('text')
});

Or you could change the type of the input to 'text' before typing and change it back after. This is bit more verbose and might not work if your app relies on the type being STRING during the typing.

cy.get('input')
.then(($input) => {
  $input[0].type = 'text'
  return $input
});
.type('text')
.then(($input) => {
  $input[0].type = 'STRING'
});

Thanks !! It solves. Using yours first solution i can write in the input but the "material" type of the input don't recognize like a correct value. But the second option changing the type of the input works. So much thank @chrisbreiding !!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jennifer-shehane picture jennifer-shehane  路  3Comments

SecondFlight picture SecondFlight  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

tahayk picture tahayk  路  3Comments