I am using mocha/node js/cypress tool to write my test scripts and able to load the data of a json file using the following statement:
var data = require('../../fixtures/TestData/JsonData/ABC_DEF.json');
If I have to pass the file name - ABC_DEF.json dynamically in the script as follows, it doesn't work.
var filename = 'ABC_DEF.json'
var data = require('../../fixtures/TestData/JsonData/'+filename);
Error I see in the Cypress console is:
Uncaught Error: Cannot find module '../../fixtures/TestData/JsonData/ABC_DEF.json'
Any inputs are highly appreciated.
Note: Objective is to read the file content whose file name is a dynamic variable and use it's value to construct the test name - it() dynamically. So file has to be read inside describe block as it has precedence over before() and it() blocks. Hence, cy commands cannot be used as they don't run outside tests and fs cannot be used as they run only in node context, again which is possible through only cy.task