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

187
Views
How to increment environment variable in 5

I want to use, each time i'm running the test suit, a different set of parameters:

{
  "Company": {
    "Name": "CompnayName1040",
    "FullName": "FullName1040",
    "phone": "0505551040"}
}

Meaning after each test run i'm running last test that will increment by 5 the above variables

When running this code the result phone number is: 05055510405

cy.readFile('cypress.env.json', ).then( (envVars) => {
cy.log('Old cypress.env.json.Employee.phone: '+envVars.Employee.phone);
envVars.Employee.phone = String(envVars.Employee.phone).replace(/(\d{4})$/, function(n){ return n+=5 });
cy.log('New cypress.env.json.Employee.phone: '+envVars.Employee.phone);
}

i was expecting the phone number to be 0505551045

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

0

If you are looking to use unique strings, you can also use the lodash, which is bundled with Cypress, function .random(). Example

Name = `CompanyName${Cypress._.random(9999)}` // random number between 0 and 9999

about 4 years ago · Juan Pablo Isaza Report

0

To bump the phone number, work with the last 7 digits.

This will preserve your leading "0".

const head = envVars.Employee.phone.substr(0,3)
const tail = envVars.Employee.phone.substr(3)
const bumped = +tail+5
envVars.Employee.phone = `${head}${bumped}`

Using @jjhelguero's idea for random numbers, you might like to try use fakerjs phoneNumber

envVars.Employee.phone = faker.phone.phoneNumber('05055510##')
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!