Use a Fixture in Cypress to Provide Response Data to Network Requests

Filip Hric
InstructorFilip Hric

Share this video with your friends

Send Tweet
Published 2 years ago
Updated 2 years ago

Instead of explicitly providing the exact body, you can choose to save the data you want to use in a separate file. When you create a file in the fixtures folder, you can reference it using fixture option in the .intercept() command. This will automatically look into the fixtures folder and load the data from the file.

Filip Hric: [0:00] Instead of explicitly providing the body, I can choose to save my response data inside a fixture file. I have saved a fixture file inside my fixtures folder. To provide this file as a response, I can go back to my spec file and type fixture and then the name of my file, which should be customList.

[0:24] Cypress will automatically know that it should look for a customList file inside the fixtures folder. Now, when I save my test, I can see that the list is taken from my fixture file.