Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda