{"__v":0,"_id":"56954a97fe18811700c9c028","category":{"__v":16,"_id":"56954a95fe18811700c9bfdf","pages":["56954a97fe18811700c9c01d","56954a97fe18811700c9c01e","56954a97fe18811700c9c01f","56954a97fe18811700c9c020","56954a97fe18811700c9c021","56954a97fe18811700c9c022","56954a97fe18811700c9c023","56954a97fe18811700c9c024","56954a97fe18811700c9c025","56954a97fe18811700c9c026","56954a97fe18811700c9c027","56954a97fe18811700c9c028","56954a97fe18811700c9c029","5696cda524490c3700170a05","5697efe61c4dc8230054268e","5697efe72cf4060d004eaa75","56993ff47465970d00650b8f","56a7a155dfdabc0d000ae910","56a7a155b5d0920d0051cd81","56a7a1a6cf6d771700baeee3","56a7a1a63d33bc2100793d5d","56a7a23097e8b00d0096d209","56a7a230ea3e3417000df4b1","56a7a25acf6d771700baeee6","56a7a25a03f28c0d00a545bf","56a7a2b83d33bc2100793d60","56a7a2b8b5d0920d0051cd82","56b27fe42db51f0d0044e566"],"project":"568fde81b700ce0d002f4b43","version":"56954a94fe18811700c9bfda","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-09T16:40:53.584Z","from_sync":false,"order":4,"slug":"guides","title":"Guides"},"parentDoc":null,"project":"568fde81b700ce0d002f4b43","user":"568fffce769f210d0013258f","version":{"__v":6,"_id":"56954a94fe18811700c9bfda","project":"568fde81b700ce0d002f4b43","createdAt":"2016-01-12T18:48:52.007Z","releaseDate":"2016-01-12T18:48:52.007Z","categories":["56954a95fe18811700c9bfdb","56954a95fe18811700c9bfdc","56954a95fe18811700c9bfdd","56954a95fe18811700c9bfde","56954a95fe18811700c9bfdf","56954a95fe18811700c9bfe0","56954a95fe18811700c9bfe1","56954a95fe18811700c9bfe2","56954a95fe18811700c9bfe3","56954a95fe18811700c9bfe4","5695649fdcaf0d1700cb8721","5696c1168560a60d00e2c1d6","56a7a32e79395317007c1ad6","5898fc3eec49fb0f004c2663","589cc675ea37da23004e05e1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"foo","version_clean":"0.0.0","version":"0.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-09T16:42:34.419Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"# Contents\n\n- :fa-angle-right: [What are Fixtures](#section-what-are-fixtures)\n- :fa-angle-right: [Supported Formats](#section-supported-formats)\n  - [Validation](#section-validation)\n  - [Formatting](#section-formatting)\n- :fa-angle-right: [Fixtures vs Factories](#section-fixtures-vs-factories)\n- :fa-angle-right: [Routing Responses](#section-routing-responses)\n- :fa-angle-right: [Organizing Fixtures](#section-organizing-fixtures)\n\n***\n\n# What are Fixtures\n\nA fixture in Cypress is a fixed set of data located in a file that is used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. Fixtures are accessed within tests by using the [`cy.fixture`](https://on.cypress.io/api/fixture) command.\n\n***\n\n# Supported Formats\n\n| File Extension |\n| --- |\n| `.coffee` |\n| `.gif` |\n| `.html` |\n| `.jpeg` |\n| `.jpg` |\n| `.js` |\n| `.json` |\n| `.png` |\n| `.txt` |\n| `.csv` |\n| `.tif` |\n| `.tiff` |\n| `.zip` |\n\n***\n\n## Validation\n\nCypress will automatically validate your fixtures. If your `.json`, `.js`, or `.coffee` files contain syntax errors, they will automatically be shown in the Command Log.\n\n***\n\n## Formatting\n\nCypress automatically formats your fixture files. That means you can paste in a single line of `json` and the next time Cypress serves this fixture, it will format / indent the `json` which makes it easier to read and debug.\n\nImage fixtures will be sent as `base64`.\n\n***\n\n# Fixtures vs Factories\n\n***\n\n# Routing Responses\n\n***\n\n# Organizing Fixtures\n\nCypress will automatically scaffold out a suggested folder structure for organizing your fixtures on every new project. By default it will create this structure when you boot your project:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"// within your project's root folder\\n/cypress/fixtures/example.json\\n\",\n            \"language\": \"text\"\n        }\n    ]\n}\n[/block]\n\nYour fixtures can be further organized within additional folders. For instance, you could create another folder called `images` and add images:\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"/cypress/fixtures/images/cats.png\\n/cypress/fixtures/images/dogs.png\\n/cypress/fixtures/images/birds.png\\n\",\n            \"language\": \"text\"\n        }\n    ]\n}\n[/block]\n\nTo access the fixtures nested within the `images` folder, simply include the folder in your [`cy.fixture`](https://on.cypress.io/api/fixture) command.\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"cy.fixture(\\\"images/dogs.png\\\") //returns dogs.png as Base64\\n\",\n            \"language\": \"javascript\"\n        }\n    ]\n}\n[/block]","excerpt":"Load fixtures","slug":"creating-fixtures","type":"basic","title":"Creating Fixtures"}

Creating Fixtures

Load fixtures

# Contents - :fa-angle-right: [What are Fixtures](#section-what-are-fixtures) - :fa-angle-right: [Supported Formats](#section-supported-formats) - [Validation](#section-validation) - [Formatting](#section-formatting) - :fa-angle-right: [Fixtures vs Factories](#section-fixtures-vs-factories) - :fa-angle-right: [Routing Responses](#section-routing-responses) - :fa-angle-right: [Organizing Fixtures](#section-organizing-fixtures) *** # What are Fixtures A fixture in Cypress is a fixed set of data located in a file that is used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. Fixtures are accessed within tests by using the [`cy.fixture`](https://on.cypress.io/api/fixture) command. *** # Supported Formats | File Extension | | --- | | `.coffee` | | `.gif` | | `.html` | | `.jpeg` | | `.jpg` | | `.js` | | `.json` | | `.png` | | `.txt` | | `.csv` | | `.tif` | | `.tiff` | | `.zip` | *** ## Validation Cypress will automatically validate your fixtures. If your `.json`, `.js`, or `.coffee` files contain syntax errors, they will automatically be shown in the Command Log. *** ## Formatting Cypress automatically formats your fixture files. That means you can paste in a single line of `json` and the next time Cypress serves this fixture, it will format / indent the `json` which makes it easier to read and debug. Image fixtures will be sent as `base64`. *** # Fixtures vs Factories *** # Routing Responses *** # Organizing Fixtures Cypress will automatically scaffold out a suggested folder structure for organizing your fixtures on every new project. By default it will create this structure when you boot your project: [block:code] { "codes": [ { "code": "// within your project's root folder\n/cypress/fixtures/example.json\n", "language": "text" } ] } [/block] Your fixtures can be further organized within additional folders. For instance, you could create another folder called `images` and add images: [block:code] { "codes": [ { "code": "/cypress/fixtures/images/cats.png\n/cypress/fixtures/images/dogs.png\n/cypress/fixtures/images/birds.png\n", "language": "text" } ] } [/block] To access the fixtures nested within the `images` folder, simply include the folder in your [`cy.fixture`](https://on.cypress.io/api/fixture) command. [block:code] { "codes": [ { "code": "cy.fixture(\"images/dogs.png\") //returns dogs.png as Base64\n", "language": "javascript" } ] } [/block]