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

291
Vistas
Not able to write splitted text in json file in cypress

I am testing an application where the alert text says like
Customer added successfully with customer id :13
Now i want to grab 13 and save it in json file. Somehow its not getting written in json file. Please help
Below is my code

export function stripcustomerid() {
cy.on('window:alert', (txt) => {
    cy.readFile('cypress/fixtures/account_details.json').then((data) => {
        var customerno = txt.split(':')
        const cno = customerno[1]
        data.customerid = cno
        cy.writeFile(
            'cypress/fixtures/account_details.json',
            JSON.stringify(data)
        )
    })
})

}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assuming that the txt variable has the string Customer added successfully with customer id :13 and also your account_details.json file has an existing customer id data like customerid: 55, because you are changing this value. Then your code looks correct.

You can replace these three lines:

var customerno = txt.split(':')
const cno = customerno[1]
data.customerid = cno

with

data.customerid = txt.split(':')[1]
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