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

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

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