I get the error code, when i coding fixtures in cypress, and if we want create fixture, we must create 2 files, first file for inizialitation fixtures and second file for main file.
and here is the code for the fixture with the file name data_sauce_demo.json
{
"username": "standard_user",
"password": "secret_sauce"
}
And here is the spec:
describe('Login with fixture data', function () {
it('Should try to login', () => {
cy.visit('https://www.saucedemo.com/');
cy.fixture('data_sauce_demo').then((user) => {
const username = user.username;
const password = user.password;
cy.get('#user-name').type(username);
cy.get('#password').type(password);
cy.contains('#login-button').click();
});
});
});
How do fix solved the problem?
You should add the fixture extension to the test code. Cypress uses the extension to know that the file contents should be interpreted as
json.Refer to docs fixture - Yields