You will need to read the file list in cypress.config.js
(for Cypress version 10 and above).
const { defineConfig } = require('cypress')
const fs = require("fs");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
const xmlFolder = `${__dirname}/xml-files/`;
const files = fs.readdirSync(xmlFolder)
.map(file => `${xmlFolder}/${file}`) // add folder path
config.xmlFiles = files // put in config for test
return config
}
}
})
In the test,
describe('Creating one test for each XML file', () => {
Cypress.config('xmlFiles')
.forEach(fileName => {
it(`Testing ${fileName}`, () => {
cy.readFile(fileName)
.then(xml => {
...
})
});
});
})
For Cypress version 9 and below use plugins.index.js
:
module.exports = (on, config) => {
on('before:run', (spec) => {
const xmlFolder = `${__dirname}/xml-files/`;
const files = fs.readdirSync(xmlFolder)
.map(file => `${xmlFolder}/${file}`) // add folder path
config.xmlFiles = files // put in config for test
})
return config
}