https://cypress.io logo
cy.writeFile does not work in headless mode (cypre...
# i-need-help
g
Hi everyone, I'm facing a really weird issue with
cy.writeFile
does not work in
cypress run
mode when writing data from the async function but works in cypress IDE
cypress open
mode Any idea why this is not working in
cypress run
mode?
Copy code
async function getSheet() {
return 'something'
}
cy.writeFile('file.js', JSON.stringify(getSheet))
g
what is the large test fragment?
g
the idea is to call async function to create an array from the spreadsheet, I found it generally impossible to call API (async function) to get some data from the spreadsheet and then use it like :
Copy code
let exercises = []

async function getSheet() {
// call sheet api
const response = await fetch(exportUrl);
// etc
return exercises
}

for (const array of exercises){
        it ('run ' + array, ()=>{
        // other cypress stuff here
  })
})
So I create a separate spec file to upload API data and then save it to the file
Copy code
async function getSheet() {
// call sheet api
const response = await fetch(exportUrl);
// etc
cy.writeFile(file_path + 'Array.js', response )

}
And if you run it from cypress IDE it works fine but when I run it from
cypress run
nothing happens
g
a) https://glebbahmutov.com/blog/setup-cypress-data/ and b) https://cypress.tips/courses/network-testing (paid course) lesson 90 shows how to fetch data if you want to create dynamic tests like that
g
Thank you! I'll check it deinetely!
7 Views