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

135
Views
Use a wraped variable in the type() function. Cypress

I'm trying to save a string with:

        cy.get('#accessInfoText').invoke('text').then($wholeText => {
            let pattern = /(?<=code: ).{10}/i;
            let number = $wholeText.match(pattern);
            cy.wrap(number).as('accessCode');
            cy.log(number);                           // AsTE5sOlJU 
        });

Later on, in the test, I need it to type it into an input field:

     cy.get('@accessCode').then(code => {
            cy.log(code);                           // [AsTE5sOlJU] 
            cy.followLabel('Access code').type(code)
        });

And my problem is that cypress converts it to an object. Which is not accepted by the .type function. enter image description here

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

0

The line let number = $wholeText.match(pattern); returns an array of all matches, even if you only have one.

Try

let number = $wholeText.match(pattern)[0];  // take first match only

If there's a possibility that there's no matches, you would need to expand it to avoid a runtime error.

const matches = $wholeText.match(pattern)
const number = matches.length ? matches[0] : null
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!