Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!