{
  "doc": {
    "id": "api/commands/fixture",
    "title": "cy.fixture()",
    "description": "Load a fixed set of data located in a file in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/fixture.md",
    "version": "29f95bf8bb06f320986f3749f5bf09a35a409eab",
    "updated_at": "2026-09-04T10:49:54.630Z",
    "headings": [
      {
        "id": "api/commands/fixture#fixture",
        "text": "fixture",
        "level": 1
      },
      {
        "id": "api/commands/fixture#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/fixture#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/fixture#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/fixture#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/fixture#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/fixture#json",
        "text": "JSON",
        "level": 3
      },
      {
        "id": "api/commands/fixture#load-a-users-json-fixture",
        "text": "Load a users.json fixture",
        "level": 4
      },
      {
        "id": "api/commands/fixture#omit-the-fixture-files-extension",
        "text": "Omit the fixture file's extension",
        "level": 4
      },
      {
        "id": "api/commands/fixture#use-import-statement",
        "text": "Use import statement",
        "level": 4
      },
      {
        "id": "api/commands/fixture#images",
        "text": "Images",
        "level": 3
      },
      {
        "id": "api/commands/fixture#image-fixtures-are-sent-as-base64-by-default",
        "text": "Image fixtures are sent as base64 by default",
        "level": 4
      },
      {
        "id": "api/commands/fixture#change-encoding-of-image-fixture",
        "text": "Change encoding of Image fixture",
        "level": 4
      },
      {
        "id": "api/commands/fixture#playing-mp3-file",
        "text": "Playing MP3 file",
        "level": 3
      },
      {
        "id": "api/commands/fixture#accessing-fixture-data",
        "text": "Accessing Fixture Data",
        "level": 3
      },
      {
        "id": "api/commands/fixture#using-then-to-access-fixture-data",
        "text": "Using .then() to access fixture data",
        "level": 4
      },
      {
        "id": "api/commands/fixture#using-fixtures-to-bootstrap-data",
        "text": "Using fixtures to bootstrap data",
        "level": 4
      },
      {
        "id": "api/commands/fixture#modifying-fixture-data-before-using-it",
        "text": "Modifying fixture data before using it",
        "level": 4
      },
      {
        "id": "api/commands/fixture#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/fixture#shortcuts",
        "text": "Shortcuts",
        "level": 3
      },
      {
        "id": "api/commands/fixture#using-the-fixture-staticresponse-property",
        "text": "Using the fixture StaticResponse property",
        "level": 4
      },
      {
        "id": "api/commands/fixture#validation",
        "text": "Validation",
        "level": 3
      },
      {
        "id": "api/commands/fixture#automated-file-validation",
        "text": "Automated File Validation",
        "level": 4
      },
      {
        "id": "api/commands/fixture#encoding",
        "text": "Encoding",
        "level": 3
      },
      {
        "id": "api/commands/fixture#default-encoding",
        "text": "Default Encoding",
        "level": 4
      },
      {
        "id": "api/commands/fixture#this-context",
        "text": "this context",
        "level": 3
      },
      {
        "id": "api/commands/fixture#large-files",
        "text": "Large Files",
        "level": 3
      },
      {
        "id": "api/commands/fixture#memory-and-transfer-constraints",
        "text": "Memory and Transfer Constraints",
        "level": 4
      },
      {
        "id": "api/commands/fixture#uploading-large-files-via-a-file-input",
        "text": "Uploading Large Files via a File Input",
        "level": 4
      },
      {
        "id": "api/commands/fixture#keeping-large-file-operations-server-side",
        "text": "Keeping Large File Operations Server-Side",
        "level": 4
      },
      {
        "id": "api/commands/fixture#loaded-just-once",
        "text": "Loaded just once",
        "level": 3
      },
      {
        "id": "api/commands/fixture#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/fixture#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/fixture#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/fixture#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/fixture#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/fixture#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "fixture"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Load a fixed set of data located in a file."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture(filePath)\ncy.fixture(filePath, encoding)\ncy.fixture(filePath, options)\ncy.fixture(filePath, encoding, options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('users').as('usersJson') // load data from users.json\ncy.fixture('logo.png').then((logo) => {\n  // load data from logo.png\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "filePath (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "A path to a file within the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/configuration.md#Folders--Files",
            "children": [
              {
                "type": "text",
                "value": "`fixturesFolder`"
              }
            ]
          },
          {
            "type": "text",
            "value": " , which defaults to `cypress/fixtures`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can nest fixtures within folders and reference them by defining the path from the fixturesFolder:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('users/admin.json') // Get data from {fixturesFolder}/users/admin.json"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "encoding (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The encoding to be used when reading the file. The following encodings are supported:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'ascii'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'base64'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'binary'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'hex'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'latin1'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'utf8'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'utf-8'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'ucs2'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'ucs-2'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'utf16le'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`'utf-16le'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`null`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Using `null` explicitly will return the fixture as a "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/utilities/buffer.md",
            "children": [
              {
                "type": "text",
                "value": "`Cypress.Buffer`"
              }
            ]
          },
          {
            "type": "text",
            "value": " instance, regardless of file extension."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `cy.fixture()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`responseTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `cy.fixture()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.fixture()` yields the contents of the file. Formatting is determined by its file extension."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "The yielded subject is not updated if the contents change on disk."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "JSON"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Load a `users.json` fixture"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('users.json').as('usersData')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Omit the fixture file's extension"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When no extension is passed to `cy.fixture()`, Cypress will search for files with the specified name within the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/configuration.md#Folders--Files",
            "children": [
              {
                "type": "text",
                "value": "`fixturesFolder`"
              }
            ]
          },
          {
            "type": "text",
            "value": " (which defaults to `cypress/fixtures`) and resolve the first one."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('admin').as('adminJSON')"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The example above would resolve in the following order:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": true,
        "start": 1,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.json`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.js`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.html`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.txt`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.csv`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.png`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.jpg`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.jpeg`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.gif`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.tif`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.tiff`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cypress/fixtures/admin.zip`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Use import statement"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If you are loading a JSON fixture, you can simply use the `import` statement and let the bundler load it:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// cypress/e2e/spec.cy.js\nimport user from '../fixtures/user.json'\nit('loads the same object', () => {\n  cy.fixture('user').then((userFixture) => {\n    expect(user, 'the same data').to.deep.equal(userFixture)\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Images"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Image fixtures are sent as `base64` by default"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('images/logo.png').then((logo) => {\n  // logo will be encoded as base64\n  // and should look something like this:\n  // aIJKnwxydrB10NVWqhlmmC+ZiWs7otHotSAAAOw==...\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Change encoding of Image fixture"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('images/logo.png', null).then((logo) => {\n  // logo will be read as a buffer\n  // and should look something like this:\n  // Buffer([0, 0, ...])\n  expect(Cypress.Buffer.isBuffer(logo)).to.be.true\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Playing MP3 file"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('audio/sound.mp3', 'base64').then((mp3) => {\n  const uri = 'data:audio/mp3;base64,' + mp3\n  const audio = new Audio(uri)\n\n  audio.play()\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Accessing Fixture Data"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Using `.then()` to access fixture data"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('users').then((json) => {\n  cy.intercept('GET', '/users/**', json)\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Using fixtures to bootstrap data"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/recipes.md#Server-Communication",
            "children": [
              {
                "type": "text",
                "value": "Check out our example recipe using `cy.fixture()` to bootstrap data for our application."
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Modifying fixture data before using it"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can modify fixture data directly before visiting a URL or mounting a component that makes a network request to that URL."
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "End-to-End Test"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Component Test"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('user').then((user) => {\n  user.firstName = 'Jane'\n  cy.intercept('GET', '/users/1', user).as('getUser')\n})\n\ncy.visit('/users')\ncy.wait('@getUser').then(({ request }) => {\n  expect(request.body.firstName).to.eq('Jane')\n})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.fixture('user').then((user) => {\n  user.firstName = 'Jane'\n  cy.intercept('GET', '/users/1', user).as('getUser')\n})\n\ncy.mount(<Users />)\ncy.wait('@getUser').then(({ request }) => {\n  expect(request.body.firstName).to.eq('Jane')\n})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Shortcuts"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Using the `fixture` `StaticResponse` property"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Fixtures can also be referenced directly without using the `.fixture()` command by using the special property `fixture` on the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/intercept.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.intercept()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " `StaticResponse` object."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.intercept('GET', '/users/**', { fixture: 'users' })"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Validation"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Automated File Validation"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress automatically validates your fixtures. If your `.json` or `.js` files contain syntax errors, they will be shown in the Command Log."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Encoding"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Default Encoding"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress automatically determines the encoding for the following file types:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.json`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.js`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.html`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.txt`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.csv`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.png`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.jpg`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.jpeg`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.gif`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.tif`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.tiff`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.zip`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For other types of files, they will be read as `utf8` by default, unless specified in the second argument of `cy.fixture()`. You can specify `null` as the encoding in order to read the file as a "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/utilities/buffer.md",
            "children": [
              {
                "type": "text",
                "value": "`Cypress.Buffer`"
              }
            ]
          },
          {
            "type": "text",
            "value": " instance instead."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "`this` context"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If you store and access the fixture data using `this` test context object, make sure to use `function () { ... }` callbacks. Otherwise the test engine will NOT have `this` pointing at the test context."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "describe('User page', () => {\n  beforeEach(function () {\n    // \"this\" points at the test context object\n    cy.fixture('user').then((user) => {\n      // \"this\" is still the test context object\n      this.user = user\n    })\n  })\n\n  // the test callback is in \"function () { ... }\" form\n  it('has user', function () {\n    // this.user exists\n    expect(this.user.firstName).to.equal('Jane')\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Large Files"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Memory and Transfer Constraints"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.fixture()` reads the entire file into memory and transfers its contents from the Cypress Node.js server process to the browser test runner over an internal WebSocket connection. There is no explicit file size limit in Cypress itself, but large files — especially binary files like `.zip` archives — can cause Cypress to crash or become unresponsive due to:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "Memory pressure: The complete file must fit in available RAM and is held in the fixture cache for the duration of the test run."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "WebSocket message size: File contents are sent as a single message over the internal socket. Payloads that approach or exceed 100 MB can exceed socket-level buffer limits."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "As a practical guideline, avoid using `cy.fixture()` with files larger than a few megabytes. Smaller test fixtures (representative subsets of production data) are preferable wherever possible."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Uploading Large Files via a File Input"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If your goal is to simulate a file upload through an `<input type=\"file\">` element, use "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/selectfile.md",
            "children": [
              {
                "type": "text",
                "value": "`.selectFile()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " with a path string rather than loading the fixture first and then setting the input manually:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// ✅ Preferred for file upload simulation\ncy.get('input[type=\"file\"]').selectFile('cypress/fixtures/large.zip')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Keeping Large File Operations Server-Side"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For scenarios where you must work with large files but do not need to transfer their full contents to the browser (for example, verifying file metadata or invoking a server-side operation), use "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/task.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.task()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " to keep the operation in the Node.js context:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// cypress.config.js\nconst { defineConfig } = require('cypress')\nconst fs = require('fs')\n\nmodule.exports = defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath) {\n          const { size } = fs.statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// in your test\ncy.task('getFileSize', 'cypress/fixtures/large.zip').then((size) => {\n  expect(size).to.be.greaterThan(0)\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Loaded just once"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Please keep in mind that fixture files are assumed to be unchanged during the test, and thus Cypress loads them just once. Even if you overwrite the fixture file itself, the already loaded fixture data remains the same."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "If you wish to dynamically change the contents of a file during your tests, consider "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/readfile.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.readFile()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " instead."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "For example, if you want to reply to a network request with different object, the following will not work:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// 🚨 DOES NOT WORK\ncy.intercept('GET', '/todos/1', { fixture: 'todo' }).as('todo')\n// application requests the /todos/1 resource\n// the intercept replies with the object from todo.json file\n\ncy.wait('@todo').then(() => {\n  cy.writeFile('/cypress/fixtures/todo.json', { title: 'New data' })\n})\n// application requests the /todos/1 resource again\n// the intercept replies with the originally loaded object\n// from the todo.json file and NOT { \"title\": \"New data\" }"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In this situation, avoid using the fixture file and instead respond to the network request with the object"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// ✅ RESPOND WITH OBJECT\ncy.fixture('todo.json').then((todo) => {\n  cy.intercept('GET', '/todos/1', { body: todo }).as('todo')\n  // application requests the /todos/1 resource\n  // the intercept replies with the initial object\n\n  cy.wait('@todo').then(() => {\n    // modify the response object\n    todo.title = 'New data'\n    // and override the intercept\n    cy.intercept('GET', '/todos/1', { body: todo })\n  })\n})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.fixture()` requires being chained off of `cy`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.fixture()` will only run assertions you have chained once, and will not "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.fixture()` should never time out."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Because `cy.fixture()` is asynchronous it is technically possible for there to be a timeout while talking to the internal Cypress automation APIs. But for practical purposes it should never happen."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.fixture()` does not log in the Command Log"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/variables-and-aliases.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Guide: Variables and Aliases"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/intercept.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.intercept()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/then.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.then()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/readfile.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.readFile()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " for a similar command without caching and with builtin retryability"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/selectfile.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.selectFile()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " for simulating file uploads, including with large files"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/task.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.task()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " for keeping large file operations in the Node.js context"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/recipes.md#Server-Communication",
                    "children": [
                      {
                        "type": "text",
                        "value": "Recipe: Bootstrapping App Test Data"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 1908
}