1

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"
    }
}

Here is a screenshot: enter image description 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());
}

The result here is an empty log. Screenshot: enter image description here

Ivan Markov
  • 129
  • 4
  • 15

0 Answers0