Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
.type() method in cypress when string is empty

Sometimes I want to pass empty string to .type() and I'm getting an error, for instance:

data = {
  "test1": "test",
  "test2": "",
};

and when I assigned first case it's work:

cy.get(...).type("test1")

The output:

test1

But when I'm passing the next one, just empty string:

cy.get(...).type("")

I've got an error that I can't provide empty string. How can I fix that?

This snippet of code is a part of a function so it must works for empty string as well as not empty string.

I tried something like this:

cy.get(...).type('{backspace}', variable)

it's working when string is empty but also skipping variable if variable contain characters.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

It's not possible for a user to type "", so neither can your test.

Use cy.get(...).clear() to make it empty.

about 4 years ago · Santiago Trujillo Relatório

0

From the comments, looks like you have already come to the solution

For example,

for (const key in data) {
  cy.get(key).type(data[key])     // fails when data[key] is empty
}

could be fixed with

for (const key in data) {
  if (data[key]) {
    cy.get(key).type(data[key])   // only type non-empty data values
  }
}
about 4 years ago · Santiago Trujillo Relatório

0

I found the answer on my own in other resources

let array = ['test1', '', 'test2', 'test3']

for (let item in array) {
  cy.get(...).type(`{backspace}` + `${item}`)
}

and its work, even if string is empty.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda