Reputation: 35
in Cypress I want to store some data into JSON file. The thing is, whenever I want to store new data, the old ones gets overwritten. Any idea how to fix this issue? Thanks.
cy.get('.form').find('.row').eq(20).find('.ng-untouched').then(opt_task => {
if (opt_task[0].innerText) {
opt_task.push({opt_task_description: opt_task[0].innerText})
} else if (opt_task[0].value) {
opt_task.push({opt_task_description: opt_task[0].value})
}
cy.writeFile(task_json, opt_task)
Upvotes: 0
Views: 205
Reputation: 18601
You have to use the flag a+
to append the new results at the end of the json rather than replacing it.
cy.writeFile(task_json, opt_task, { flag: 'a+' })
Upvotes: 1