I've got multiple json files in a folder which i need to read one by one for testing API. How can i read each file and use it in a different test.
Currently I'm reading files using cy.task(), but cy.task() is not available outside it()
describe("Test JSON", () => {
it(`get file located on test folder`, () => {
cy.task("getFiles", "cypress/fixtures/jsons/").then((files) => {
files.forEach((file) => {
cy.fixture(`jsons/${file}`).then((testJson) => {
cy.request({
method: "POST",
url: Cypress.config().baseUrl,
body: testJson,
}).then((response) => {
expect(response.status).equal(200);
});
});
});
});
});
});
(getFiles is a plugin to read filenames in a directory using fs)
How can i run different tests for different files?