I am trying to access config data from a JSON file (in Cypress). The code is working fine if I use one function:
workingFunction() {
var data;
cy.fixture('env/environments').then((readedData) => {
data = readedData;
cy.log(data.clientEnvironment.qa);
});
}
Here is an example of my JSON file:
{
"clientEnvironment": {
"qa": "hardcode clients url here"
}
}
But if I try to split the logic into two functions (in one class) - it seems that I am not able to read the JSON file data from another function.
Here is my code:
readDataFunction(): any {
let data;
cy.fixture('env/environments').then((readedData) => {
return data = readedData;
});
}
secondFunction() {
cy.log(this.readDataFunction());
}