question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.type() can only accept a string or number. You passed in: 'undefined'

See original GitHub issue

Current behavior:

When I try to get data form a Json file, this message shown. The question: Can I get text from a Json file?

image

Desired behavior:

I Need to insert this data (that the Json file have) in the text area

Steps to reproduce: (app code and test code)

Test

beforeEach(() => {
        cy.server()
        cy.fixture("licencia.json").then((data) => {
            cy.route('GET', 'licencia.json', data)
        })
it.only('POST - Add License', function () {
        cy.get('[id=operations-License-Post]').children('div').click()
          .get('button').contains('Try it out').click()
        cy.get('textarea').clear()
          .get('textarea').type(this.data)

** Json Example/format**

  {
      "nombres": "Pulga",
      "apellido": "Rodriguez",
      "tipoDocumento": "NOT_DEFINED",
      "fechaNacimiento": "1986-08-10T17:40:08.484Z",
      "nroLicencia": "32001001",
      "cuil": "20320010013",
      "domicilio": "25 de mayo 1350",
      "nacionalidad": "Argentino",
      "sexo": "Masculino",
      "grupoFactor": "0+",
      "nroTramite": "251350",
      "numeroInsumo": "string 1",
      "fechaOtorgamiento": "2019-07-26T17:40:08.484Z",
      "fechaRenovacion": "2019-07-26T17:40:08.484Z",
      "fechaVencimiento": "2019-07-26T17:40:08.484Z",
      "categoria": "A",
      "clase": "1",
      "restricciones": "ninguna",
      "observaciones": "cinco",
      "centroEmisor": "Las Talitas",
      "donante": true,
      "firmante": "Leito",
      "estado": "Vigente"
    }```
<!-- Issues without reproducible steps WILL BE CLOSED -->

<!-- You can fork https://github.com/cypress-io/cypress-test-tiny repo, set up a failing test, then tell us the repo/branch to try. -->

### Versions

<!-- Cypress, operating system, browser -->
win10
Chrome v75

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bahmutovcommented, Jul 30, 2019

so the JSON from the fixture is automatically parsed and converted into an object, right? You probably want to type it as text. This should do the trick

cy.get('textarea').type(JSON.stringify(this.data))
Read more comments on GitHub >

github_iconTop Results From Across the Web

CypressError: `cy.type()` can only accept a string or number ...
It's caused by sending undefined as a parameter to cy.type() , the error message does not lie (most likely anyway). I assume you...
Read more >
cypress-io/cypress - Gitter
CypressError : cy.type() can only accept a String or Number. You passed in: 'undefined'. my code is the follwing: describe('Loops between given users', ......
Read more >
type - Cypress Documentation
The text to be typed into the DOM element. Text passed to .type() may include any of the special character sequences below. These...
Read more >
CypressError: `cy.type()` can only accept a string or number ...
Coding example for the question Docker and Cypress - CypressError: `cy.type()` can only accept a string or number. You passed in: `undefined`-docker.
Read more >
Cypress Type Command - ProgramsBuzz
Text(String). Here comes the text to be typed into the DOM element. These characters will pass along the correct keyCode, key, and which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found