Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
How to pass variables / aliases between Cypress step definitions?

I am trying to re-use a variable or alias across multiple step definitions in my Cypress / Cucumber test.

Variable declaration & 1st step def:

let assetName = '';

And('I click on the button', (view) => {   
  if (view === 'Grid') {
    homePage.getAssetName().first().then($el => {
    assetName = $el.text();
    }).click();
  }
});

2nd step def:

And('I verify something', (view) => {   
    cy.get('.ItgAssetDetails-name').should('have.text', + assetName);
});

But I get the below error message:

expected <p.ItgAssetDetails-name> to have text NaN, but the text was lenses System

I've also tried assigning $el.text() an alias, but that hasn't worked either.

Can someone please show me what changes are required to pass this value between step definitions?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your problem is likely a typo since you are calling .should('have.text', + assetName). The + is a unary operator trying to convert your string in assetName into a number and giving you NaN

console.log(+"Hello there")

Just remove the +

.should('have.text', assetName)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda