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

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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