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

226
Views
Use a variable outside of a function in Cypress

I want to use a value that i got from a website and stored in a variable outside of a "within" function to comapre it with another value.

cy.get('.TableCloumn_3')
    .within($tr => {
     cy.get('[class="ng-star-inserted"]').then(($span) => {

    const relRep = $span.text();
   
     cy.log(relRep);
      })
    })
    
  
   cy.log(relRep) 
    
  })

The first cy.log for relRep prints me the value but the second one does not. When I change from it from cont to var it also gives me an empty log. How can i use this value outside the function?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can initialize a variable at the top level and assign it inside the function

let foo

function bar() {
  foo = "1"
}
bar()
console.log(foo)

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!