Within Cypress I am opening a JSON file and I want to use values within that file to check in a test.
I open the file using cy.readfile() this is my code to read:
let expectedTimeOfTest = "";
cy.readFile(filePath + fileName).then((json) => {
expect(json).to.be.an('object')
expectedTimeOfTest = JSON.stringify(json.SEQUENCE.timeoftest);
cy.log(">>" + expectedTimeOfTest);
});
When I run the test, I can see in the runner that the text appears in the log as I expect.
Now later on I try to assert, I use:
cy.get('.testClass').eq(1).should('have.text', expectedTimeOfTest);
However, the test fails with the error "expected .testClass to be '' but got ''
I cannot see what I have done wrong? Any ideas?