{
  "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": "f97f06d85653c51afe39a9bd3cefda946807f150",
    "updated_at": "2026-10-05T21:01:45.863Z",
    "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#import-a-json-fixture-into-your-spec",
        "text": "Import a JSON fixture into your spec",
        "level": 4
      },
      {
        "id": "api/commands/fixture#generate-a-test-for-each-record-in-a-fixture",
        "text": "Generate a test for each record in a fixture",
        "level": 4
      },
      {
        "id": "api/commands/fixture#type-fixture-data-in-typescript",
        "text": "Type fixture data in TypeScript",
        "level": 4
      },
      {
        "id": "api/commands/fixture#read-a-json-fixture-as-raw-text",
        "text": "Read a JSON fixture as raw text",
        "level": 4
      },
      {
        "id": "api/commands/fixture#images",
        "text": "Images",
        "level": 3
      },
      {
        "id": "api/commands/fixture#image-fixtures-yield-base64-strings-by-default",
        "text": "Image fixtures yield base64 strings by default",
        "level": 4
      },
      {
        "id": "api/commands/fixture#read-an-image-fixture-as-a-cypress-buffer",
        "text": "Read an image fixture as a Cypress.Buffer",
        "level": 4
      },
      {
        "id": "api/commands/fixture#file-uploads",
        "text": "File uploads",
        "level": 3
      },
      {
        "id": "api/commands/fixture#upload-a-fixture-with-selectfile",
        "text": "Upload a fixture with .selectFile()",
        "level": 4
      },
      {
        "id": "api/commands/fixture#audio",
        "text": "Audio",
        "level": 3
      },
      {
        "id": "api/commands/fixture#play-an-mp3-fixture-in-the-browser",
        "text": "Play an MP3 fixture in the browser",
        "level": 4
      },
      {
        "id": "api/commands/fixture#accessing-fixture-data",
        "text": "Accessing fixture data",
        "level": 3
      },
      {
        "id": "api/commands/fixture#stub-a-network-response-with-fixture-data",
        "text": "Stub a network response with fixture data",
        "level": 4
      },
      {
        "id": "api/commands/fixture#load-a-fixture-in-beforeeach-and-read-it-with-cy-get",
        "text": "Load a fixture in beforeEach() and read it with cy.get()",
        "level": 4
      },
      {
        "id": "api/commands/fixture#bootstrap-your-apps-data-with-fixtures",
        "text": "Bootstrap your app's data with fixtures",
        "level": 4
      },
      {
        "id": "api/commands/fixture#change-fixture-data-before-stubbing-a-response",
        "text": "Change fixture data before stubbing a response",
        "level": 4
      },
      {
        "id": "api/commands/fixture#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/fixture#how-cy-fixture-differs-from-cy-readfile",
        "text": "How cy.fixture() differs from cy.readFile()",
        "level": 3
      },
      {
        "id": "api/commands/fixture#serve-a-fixture-directly-from-cy-intercept",
        "text": "Serve a fixture directly from cy.intercept()",
        "level": 3
      },
      {
        "id": "api/commands/fixture#how-cypress-validates-json-and-javascript-fixtures",
        "text": "How Cypress validates JSON and JavaScript fixtures",
        "level": 3
      },
      {
        "id": "api/commands/fixture#how-cypress-chooses-a-fixtures-encoding",
        "text": "How Cypress chooses a fixture's encoding",
        "level": 3
      },
      {
        "id": "api/commands/fixture#sharing-fixture-data-through-the-this-context",
        "text": "Sharing fixture data through the this context",
        "level": 3
      },
      {
        "id": "api/commands/fixture#loading-large-files-with-cy-fixture",
        "text": "Loading large files with cy.fixture()",
        "level": 3
      },
      {
        "id": "api/commands/fixture#why-large-fixtures-can-crash-or-stall-cypress",
        "text": "Why large fixtures can crash or stall Cypress",
        "level": 4
      },
      {
        "id": "api/commands/fixture#upload-a-large-file-with-selectfile-and-a-path",
        "text": "Upload a large file with .selectFile() and a path",
        "level": 4
      },
      {
        "id": "api/commands/fixture#check-a-large-file-in-node-js-with-cy-task",
        "text": "Check a large file in Node.js with cy.task()",
        "level": 4
      },
      {
        "id": "api/commands/fixture#how-cypress-caches-fixture-data",
        "text": "How Cypress caches fixture data",
        "level": 3
      },
      {
        "id": "api/commands/fixture#fixtures-in-cy-intercept-are-read-when-the-route-is-added",
        "text": "Fixtures in cy.intercept() are read when the route is added",
        "level": 4
      },
      {
        "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#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/fixture#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/fixture#syntax",
      "doc_id": "api/commands/fixture",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.fixture(filePath)\ncy.fixture(filePath, encoding)\ncy.fixture(filePath, options)\ncy.fixture(filePath, encoding, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.fixture('users').as('usersJson') // load data from users.json\ncy.fixture('logo.png').then((logo) => {\n  // load data from logo.png\n})\n```\n\n### Arguments\n\n**filePath _(String)_**\n\nA path to a file within the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) , which defaults to `cypress/fixtures`.\n\nYou can nest fixtures within folders and reference them by defining the path from the fixturesFolder:\n\n```\ncy.fixture('users/admin.json') // Get data from {fixturesFolder}/users/admin.json\n```\n\n**encoding _(String)_**\n\nThe encoding to be used when reading the file. The following encodings are supported:\n\n*   `'ascii'`\n*   `'base64'`\n*   `'binary'`\n*   `'hex'`\n*   `'latin1'`\n*   `'utf8'`\n*   `'utf-8'`\n*   `'ucs2'`\n*   `'ucs-2'`\n*   `'utf16le'`\n*   `'utf-16le'`\n*   `null`\n\nPassing an encoding yields the raw file contents without parsing them, whatever the file extension. For example, `cy.fixture('users.json', 'utf8')` yields the JSON as a string rather than an object. Passing `null` yields the contents as a [`Cypress.Buffer`](/llm/markdown/api/utilities/buffer.md) instance.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.fixture()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.fixture()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `cy.fixture()` yields the contents of the file. Formatting is determined by its file extension, unless you pass an `encoding`.\n*   `cy.fixture()` yields a copy of the cached contents, so changing the yielded object does not affect later `cy.fixture()` calls for the same file.\n*   The yielded subject is **not** updated if the contents change on disk. See [How Cypress caches fixture data](#How-Cypress-caches-fixture-data) for when Cypress reads the file again.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 357
    },
    {
      "id": "api/commands/fixture#arguments",
      "doc_id": "api/commands/fixture",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**filePath _(String)_**\n\nA path to a file within the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) , which defaults to `cypress/fixtures`.\n\nYou can nest fixtures within folders and reference them by defining the path from the fixturesFolder:\n\n```\ncy.fixture('users/admin.json') // Get data from {fixturesFolder}/users/admin.json\n```\n\n**encoding _(String)_**\n\nThe encoding to be used when reading the file. The following encodings are supported:\n\n*   `'ascii'`\n*   `'base64'`\n*   `'binary'`\n*   `'hex'`\n*   `'latin1'`\n*   `'utf8'`\n*   `'utf-8'`\n*   `'ucs2'`\n*   `'ucs-2'`\n*   `'utf16le'`\n*   `'utf-16le'`\n*   `null`\n\nPassing an encoding yields the raw file contents without parsing them, whatever the file extension. For example, `cy.fixture('users.json', 'utf8')` yields the JSON as a string rather than an object. Passing `null` yields the contents as a [`Cypress.Buffer`](/llm/markdown/api/utilities/buffer.md) instance.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.fixture()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.fixture()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 217
    },
    {
      "id": "api/commands/fixture#yields",
      "doc_id": "api/commands/fixture",
      "heading": "Yields",
      "heading_level": 3,
      "content_markdown": "### Yields\n\n*   `cy.fixture()` yields the contents of the file. Formatting is determined by its file extension, unless you pass an `encoding`.\n*   `cy.fixture()` yields a copy of the cached contents, so changing the yielded object does not affect later `cy.fixture()` calls for the same file.\n*   The yielded subject is **not** updated if the contents change on disk. See [How Cypress caches fixture data](#How-Cypress-caches-fixture-data) for when Cypress reads the file again.\n",
      "section": "api",
      "anchors": [
        "yields"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/fixture#examples",
      "doc_id": "api/commands/fixture",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### JSON\n\n#### Load a `users.json` fixture\n\n```\ncy.fixture('users.json').as('usersData')\n```\n\n#### Omit the fixture file's extension\n\nWhen no extension is passed to `cy.fixture()`, Cypress first looks for a file with exactly that name. If there isn't one, Cypress searches for files with the specified name and a supported extension within the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) (which defaults to `cypress/fixtures`) and resolves the first one.\n\n```\ncy.fixture('admin').as('adminJSON')\n```\n\nThe example above would resolve in the following order:\n\n1.  `cypress/fixtures/admin.json`\n2.  `cypress/fixtures/admin.js`\n3.  `cypress/fixtures/admin.html`\n4.  `cypress/fixtures/admin.txt`\n5.  `cypress/fixtures/admin.csv`\n6.  `cypress/fixtures/admin.png`\n7.  `cypress/fixtures/admin.jpg`\n8.  `cypress/fixtures/admin.jpeg`\n9.  `cypress/fixtures/admin.gif`\n10.  `cypress/fixtures/admin.tif`\n11.  `cypress/fixtures/admin.tiff`\n12.  `cypress/fixtures/admin.zip`\n\n#### Import a JSON fixture into your spec\n\nIf you are loading a JSON fixture, you can use the `import` statement and let the bundler load it:\n\ncypress/e2e/spec.cy.js\n\n```\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})\n```\n\n#### Generate a test for each record in a fixture\n\nTo create one test per fixture record, `import` the fixture. `cy.fixture()` supplies data inside a test, but a loop inside its callback can't add new `it()` blocks.\n\ncypress/e2e/users.cy.js\n\n```\nimport users from '../fixtures/users.json'\n\ndescribe('User profiles', () => {\n  users.forEach((user) => {\n    it(`shows the profile for ${user.name}`, () => {\n      cy.visit(`/users/${user.id}`)\n      cy.contains('h1', user.name)\n    })\n  })\n})\n```\n\n#### Type fixture data in TypeScript\n\n`cy.fixture()` accepts a type argument that describes the yielded contents. Cypress doesn't check the file against the type, so keep the two in sync.\n\n```\ntype User = {\n  id: number\n  name: string\n  email: string\n}\n\ncy.fixture<User[]>('users').then((users) => {\n  // users is typed as User[]\n  cy.get('[data-cy=\"user-email\"]').first().should('have.text', users[0].email)\n})\n```\n\n#### Read a JSON fixture as raw text\n\nPass an encoding to yield the file's contents as a string instead of the parsed object. This helps when you want the exact text of the file, such as to compare it with a raw request body.\n\n```\ncy.fixture('users.json', 'utf8').then((raw) => {\n  expect(raw).to.be.a('string')\n  expect(raw).to.include('\"email\"')\n})\n```\n\n### Images\n\n#### Image fixtures yield `base64` strings by default\n\n```\ncy.fixture('images/logo.png').then((logo) => {\n  // logo will be encoded as base64\n  // and should look something like this:\n  // aIJKnwxydrB10NVWqhlmmC+ZiWs7otHotSAAAOw==...\n})\n```\n\n#### Read an image fixture as a `Cypress.Buffer`\n\n```\ncy.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})\n```\n\n### File uploads\n\n#### Upload a fixture with `.selectFile()`\n\nLoad the fixture with a `null` encoding so it yields a `Cypress.Buffer`, alias it, and pass the alias to [`.selectFile()`](/llm/markdown/api/commands/selectfile.md). Cypress keeps the fixture's file name, so the upload arrives as `avatar.png`.\n\n```\ncy.fixture('images/avatar.png', null).as('avatar')\ncy.get('input[type=\"file\"]').selectFile('@avatar')\n```\n\n### Audio\n\n#### Play an MP3 fixture in the browser\n\n```\ncy.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})\n```\n\n### Accessing fixture data\n\n#### Stub a network response with fixture data\n\n```\ncy.fixture('users').then((json) => {\n  cy.intercept('GET', '/users/**', json)\n})\n```\n\n#### Load a fixture in `beforeEach()` and read it with `cy.get()`\n\nAliases are cleared between tests, so load the fixture in a `beforeEach()` hook and read the alias back with [`cy.get()`](/llm/markdown/api/commands/get.md#Alias). This works with arrow functions, unlike the [`this` context](#Sharing-fixture-data-through-the-this-context).\n\n```\ndescribe('User list', () => {\n  beforeEach(() => {\n    cy.fixture('users').as('users')\n  })\n\n  it('shows a row for every user', () => {\n    cy.visit('/users')\n    cy.get('@users').then((users) => {\n      cy.get('[data-cy=\"user-row\"]').should('have.length', users.length)\n    })\n  })\n})\n```\n\n#### Bootstrap your app's data with fixtures\n\n[Check out our example recipe using `cy.fixture()` to bootstrap data for our application.](/llm/markdown/app/references/recipes.md#Server-Communication)\n\n#### Change fixture data before stubbing a response\n\nYou can modify fixture data directly before visiting a URL or mounting a component that makes a network request to that URL.\n\n*   End-to-End Test\n*   Component Test\n\n```\ncy.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(({ response }) => {\n  expect(response.body.firstName).to.eq('Jane')\n})\n```\n\n```\ncy.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(({ response }) => {\n  expect(response.body.firstName).to.eq('Jane')\n})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 872
    },
    {
      "id": "api/commands/fixture#json",
      "doc_id": "api/commands/fixture",
      "heading": "JSON",
      "heading_level": 3,
      "content_markdown": "### JSON\n\n#### Load a `users.json` fixture\n\n```\ncy.fixture('users.json').as('usersData')\n```\n\n#### Omit the fixture file's extension\n\nWhen no extension is passed to `cy.fixture()`, Cypress first looks for a file with exactly that name. If there isn't one, Cypress searches for files with the specified name and a supported extension within the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) (which defaults to `cypress/fixtures`) and resolves the first one.\n\n```\ncy.fixture('admin').as('adminJSON')\n```\n\nThe example above would resolve in the following order:\n\n1.  `cypress/fixtures/admin.json`\n2.  `cypress/fixtures/admin.js`\n3.  `cypress/fixtures/admin.html`\n4.  `cypress/fixtures/admin.txt`\n5.  `cypress/fixtures/admin.csv`\n6.  `cypress/fixtures/admin.png`\n7.  `cypress/fixtures/admin.jpg`\n8.  `cypress/fixtures/admin.jpeg`\n9.  `cypress/fixtures/admin.gif`\n10.  `cypress/fixtures/admin.tif`\n11.  `cypress/fixtures/admin.tiff`\n12.  `cypress/fixtures/admin.zip`\n\n#### Import a JSON fixture into your spec\n\nIf you are loading a JSON fixture, you can use the `import` statement and let the bundler load it:\n\ncypress/e2e/spec.cy.js\n\n```\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})\n```\n\n#### Generate a test for each record in a fixture\n\nTo create one test per fixture record, `import` the fixture. `cy.fixture()` supplies data inside a test, but a loop inside its callback can't add new `it()` blocks.\n\ncypress/e2e/users.cy.js\n\n```\nimport users from '../fixtures/users.json'\n\ndescribe('User profiles', () => {\n  users.forEach((user) => {\n    it(`shows the profile for ${user.name}`, () => {\n      cy.visit(`/users/${user.id}`)\n      cy.contains('h1', user.name)\n    })\n  })\n})\n```\n\n#### Type fixture data in TypeScript\n\n`cy.fixture()` accepts a type argument that describes the yielded contents. Cypress doesn't check the file against the type, so keep the two in sync.\n\n```\ntype User = {\n  id: number\n  name: string\n  email: string\n}\n\ncy.fixture<User[]>('users').then((users) => {\n  // users is typed as User[]\n  cy.get('[data-cy=\"user-email\"]').first().should('have.text', users[0].email)\n})\n```\n\n#### Read a JSON fixture as raw text\n\nPass an encoding to yield the file's contents as a string instead of the parsed object. This helps when you want the exact text of the file, such as to compare it with a raw request body.\n\n```\ncy.fixture('users.json', 'utf8').then((raw) => {\n  expect(raw).to.be.a('string')\n  expect(raw).to.include('\"email\"')\n})\n```\n",
      "section": "api",
      "anchors": [
        "json"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 429
    },
    {
      "id": "api/commands/fixture#omit-the-fixture-files-extension",
      "doc_id": "api/commands/fixture",
      "heading": "Omit the fixture file's extension",
      "heading_level": 4,
      "content_markdown": "#### Omit the fixture file's extension\n\nWhen no extension is passed to `cy.fixture()`, Cypress first looks for a file with exactly that name. If there isn't one, Cypress searches for files with the specified name and a supported extension within the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) (which defaults to `cypress/fixtures`) and resolves the first one.\n\n```\ncy.fixture('admin').as('adminJSON')\n```\n\nThe example above would resolve in the following order:\n\n1.  `cypress/fixtures/admin.json`\n2.  `cypress/fixtures/admin.js`\n3.  `cypress/fixtures/admin.html`\n4.  `cypress/fixtures/admin.txt`\n5.  `cypress/fixtures/admin.csv`\n6.  `cypress/fixtures/admin.png`\n7.  `cypress/fixtures/admin.jpg`\n8.  `cypress/fixtures/admin.jpeg`\n9.  `cypress/fixtures/admin.gif`\n10.  `cypress/fixtures/admin.tif`\n11.  `cypress/fixtures/admin.tiff`\n12.  `cypress/fixtures/admin.zip`\n",
      "section": "api",
      "anchors": [
        "omit-the-fixture-files-extension"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 116
    },
    {
      "id": "api/commands/fixture#import-a-json-fixture-into-your-spec",
      "doc_id": "api/commands/fixture",
      "heading": "Import a JSON fixture into your spec",
      "heading_level": 4,
      "content_markdown": "#### Import a JSON fixture into your spec\n\nIf you are loading a JSON fixture, you can use the `import` statement and let the bundler load it:\n\ncypress/e2e/spec.cy.js\n\n```\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})\n```\n",
      "section": "api",
      "anchors": [
        "import-a-json-fixture-into-your-spec"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/fixture#generate-a-test-for-each-record-in-a-fixture",
      "doc_id": "api/commands/fixture",
      "heading": "Generate a test for each record in a fixture",
      "heading_level": 4,
      "content_markdown": "#### Generate a test for each record in a fixture\n\nTo create one test per fixture record, `import` the fixture. `cy.fixture()` supplies data inside a test, but a loop inside its callback can't add new `it()` blocks.\n\ncypress/e2e/users.cy.js\n\n```\nimport users from '../fixtures/users.json'\n\ndescribe('User profiles', () => {\n  users.forEach((user) => {\n    it(`shows the profile for ${user.name}`, () => {\n      cy.visit(`/users/${user.id}`)\n      cy.contains('h1', user.name)\n    })\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "generate-a-test-for-each-record-in-a-fixture"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 88
    },
    {
      "id": "api/commands/fixture#type-fixture-data-in-typescript",
      "doc_id": "api/commands/fixture",
      "heading": "Type fixture data in TypeScript",
      "heading_level": 4,
      "content_markdown": "#### Type fixture data in TypeScript\n\n`cy.fixture()` accepts a type argument that describes the yielded contents. Cypress doesn't check the file against the type, so keep the two in sync.\n\n```\ntype User = {\n  id: number\n  name: string\n  email: string\n}\n\ncy.fixture<User[]>('users').then((users) => {\n  // users is typed as User[]\n  cy.get('[data-cy=\"user-email\"]').first().should('have.text', users[0].email)\n})\n```\n",
      "section": "api",
      "anchors": [
        "type-fixture-data-in-typescript"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 73
    },
    {
      "id": "api/commands/fixture#read-a-json-fixture-as-raw-text",
      "doc_id": "api/commands/fixture",
      "heading": "Read a JSON fixture as raw text",
      "heading_level": 4,
      "content_markdown": "#### Read a JSON fixture as raw text\n\nPass an encoding to yield the file's contents as a string instead of the parsed object. This helps when you want the exact text of the file, such as to compare it with a raw request body.\n\n```\ncy.fixture('users.json', 'utf8').then((raw) => {\n  expect(raw).to.be.a('string')\n  expect(raw).to.include('\"email\"')\n})\n```\n",
      "section": "api",
      "anchors": [
        "read-a-json-fixture-as-raw-text"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/fixture#images",
      "doc_id": "api/commands/fixture",
      "heading": "Images",
      "heading_level": 3,
      "content_markdown": "### Images\n\n#### Image fixtures yield `base64` strings by default\n\n```\ncy.fixture('images/logo.png').then((logo) => {\n  // logo will be encoded as base64\n  // and should look something like this:\n  // aIJKnwxydrB10NVWqhlmmC+ZiWs7otHotSAAAOw==...\n})\n```\n\n#### Read an image fixture as a `Cypress.Buffer`\n\n```\ncy.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})\n```\n",
      "section": "api",
      "anchors": [
        "images"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 89
    },
    {
      "id": "api/commands/fixture#image-fixtures-yield-base64-strings-by-default",
      "doc_id": "api/commands/fixture",
      "heading": "Image fixtures yield base64 strings by default",
      "heading_level": 4,
      "content_markdown": "#### Image fixtures yield `base64` strings by default\n\n```\ncy.fixture('images/logo.png').then((logo) => {\n  // logo will be encoded as base64\n  // and should look something like this:\n  // aIJKnwxydrB10NVWqhlmmC+ZiWs7otHotSAAAOw==...\n})\n```\n",
      "section": "api",
      "anchors": [
        "image-fixtures-yield-base64-strings-by-default"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/fixture#read-an-image-fixture-as-a-cypress-buffer",
      "doc_id": "api/commands/fixture",
      "heading": "Read an image fixture as a Cypress.Buffer",
      "heading_level": 4,
      "content_markdown": "#### Read an image fixture as a `Cypress.Buffer`\n\n```\ncy.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})\n```\n",
      "section": "api",
      "anchors": [
        "read-an-image-fixture-as-a-cypress-buffer"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 47
    },
    {
      "id": "api/commands/fixture#file-uploads",
      "doc_id": "api/commands/fixture",
      "heading": "File uploads",
      "heading_level": 3,
      "content_markdown": "### File uploads\n\n#### Upload a fixture with `.selectFile()`\n\nLoad the fixture with a `null` encoding so it yields a `Cypress.Buffer`, alias it, and pass the alias to [`.selectFile()`](/llm/markdown/api/commands/selectfile.md). Cypress keeps the fixture's file name, so the upload arrives as `avatar.png`.\n\n```\ncy.fixture('images/avatar.png', null).as('avatar')\ncy.get('input[type=\"file\"]').selectFile('@avatar')\n```\n",
      "section": "api",
      "anchors": [
        "file-uploads"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 61
    },
    {
      "id": "api/commands/fixture#upload-a-fixture-with-selectfile",
      "doc_id": "api/commands/fixture",
      "heading": "Upload a fixture with .selectFile()",
      "heading_level": 4,
      "content_markdown": "#### Upload a fixture with `.selectFile()`\n\nLoad the fixture with a `null` encoding so it yields a `Cypress.Buffer`, alias it, and pass the alias to [`.selectFile()`](/llm/markdown/api/commands/selectfile.md). Cypress keeps the fixture's file name, so the upload arrives as `avatar.png`.\n\n```\ncy.fixture('images/avatar.png', null).as('avatar')\ncy.get('input[type=\"file\"]').selectFile('@avatar')\n```\n",
      "section": "api",
      "anchors": [
        "upload-a-fixture-with-selectfile"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/fixture#accessing-fixture-data",
      "doc_id": "api/commands/fixture",
      "heading": "Accessing fixture data",
      "heading_level": 3,
      "content_markdown": "### Accessing fixture data\n\n#### Stub a network response with fixture data\n\n```\ncy.fixture('users').then((json) => {\n  cy.intercept('GET', '/users/**', json)\n})\n```\n\n#### Load a fixture in `beforeEach()` and read it with `cy.get()`\n\nAliases are cleared between tests, so load the fixture in a `beforeEach()` hook and read the alias back with [`cy.get()`](/llm/markdown/api/commands/get.md#Alias). This works with arrow functions, unlike the [`this` context](#Sharing-fixture-data-through-the-this-context).\n\n```\ndescribe('User list', () => {\n  beforeEach(() => {\n    cy.fixture('users').as('users')\n  })\n\n  it('shows a row for every user', () => {\n    cy.visit('/users')\n    cy.get('@users').then((users) => {\n      cy.get('[data-cy=\"user-row\"]').should('have.length', users.length)\n    })\n  })\n})\n```\n\n#### Bootstrap your app's data with fixtures\n\n[Check out our example recipe using `cy.fixture()` to bootstrap data for our application.](/llm/markdown/app/references/recipes.md#Server-Communication)\n\n#### Change fixture data before stubbing a response\n\nYou can modify fixture data directly before visiting a URL or mounting a component that makes a network request to that URL.\n\n*   End-to-End Test\n*   Component Test\n\n```\ncy.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(({ response }) => {\n  expect(response.body.firstName).to.eq('Jane')\n})\n```\n\n```\ncy.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(({ response }) => {\n  expect(response.body.firstName).to.eq('Jane')\n})\n```\n",
      "section": "api",
      "anchors": [
        "accessing-fixture-data"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 251
    },
    {
      "id": "api/commands/fixture#load-a-fixture-in-beforeeach-and-read-it-with-cy-get",
      "doc_id": "api/commands/fixture",
      "heading": "Load a fixture in beforeEach() and read it with cy.get()",
      "heading_level": 4,
      "content_markdown": "#### Load a fixture in `beforeEach()` and read it with `cy.get()`\n\nAliases are cleared between tests, so load the fixture in a `beforeEach()` hook and read the alias back with [`cy.get()`](/llm/markdown/api/commands/get.md#Alias). This works with arrow functions, unlike the [`this` context](#Sharing-fixture-data-through-the-this-context).\n\n```\ndescribe('User list', () => {\n  beforeEach(() => {\n    cy.fixture('users').as('users')\n  })\n\n  it('shows a row for every user', () => {\n    cy.visit('/users')\n    cy.get('@users').then((users) => {\n      cy.get('[data-cy=\"user-row\"]').should('have.length', users.length)\n    })\n  })\n})\n```\n",
      "section": "api",
      "anchors": [
        "load-a-fixture-in-beforeeach-and-read-it-with-cy-get"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/fixture#change-fixture-data-before-stubbing-a-response",
      "doc_id": "api/commands/fixture",
      "heading": "Change fixture data before stubbing a response",
      "heading_level": 4,
      "content_markdown": "#### Change fixture data before stubbing a response\n\nYou can modify fixture data directly before visiting a URL or mounting a component that makes a network request to that URL.\n\n*   End-to-End Test\n*   Component Test\n\n```\ncy.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(({ response }) => {\n  expect(response.body.firstName).to.eq('Jane')\n})\n```\n\n```\ncy.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(({ response }) => {\n  expect(response.body.firstName).to.eq('Jane')\n})\n```\n",
      "section": "api",
      "anchors": [
        "change-fixture-data-before-stubbing-a-response"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 103
    },
    {
      "id": "api/commands/fixture#notes",
      "doc_id": "api/commands/fixture",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### How `cy.fixture()` differs from `cy.readFile()`\n\nBoth commands read a file from disk, but they answer different questions. `cy.fixture()` answers \"what data should this test start with?\" while [`cy.readFile()`](/llm/markdown/api/commands/readfile.md) answers \"what's in this file right now?\" Use `cy.fixture()` for known data that stays the same during the run, and `cy.readFile()` for files that change or that your app creates. For when to reach for a static `import` or [`cy.task()`](/llm/markdown/api/commands/task.md) instead, see [Choosing how to load test data in Cypress](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Choosing-how-to-load-test-data-in-Cypress).\n\n|  | `cy.fixture()` | `cy.readFile()` |\n| --- | --- | --- |\n| Path is relative to | `fixturesFolder` | The project root |\n| File extension | Optional | Required |\n| Reads from disk | Once per path and encoding, then yields the cached copy | On every call |\n| Retries until assertions pass | No | Yes, reading the file again on each retry |\n| Images by default | A `base64` string | A `utf8` string |\n| Default timeout | `responseTimeout` | `defaultCommandTimeout` |\n| Command Log | Not logged | Logged |\n| Missing file | Always fails | Can be asserted with `.should('not.exist')` |\n\n### Serve a fixture directly from `cy.intercept()`\n\nFixtures can also be referenced directly without using the `cy.fixture()` command by using the special property `fixture` on the [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) `StaticResponse` object.\n\n```\ncy.intercept('GET', '/users/**', { fixture: 'users' })\n```\n\nThe Command Log's **Routes** panel lists the route as stubbed, and each request it answers appears in the test body without a live server behind it:\n\n`cy.intercept()` serves image and `.zip` fixtures as raw bytes. Other binary files, such as `.mp4` or `.pdf`, are read as `utf8` text by default, which corrupts them. To serve one of those byte for byte, add `null` as the encoding after a comma:\n\n```\ncy.intercept('GET', '/media/intro.mp4', { fixture: 'media/intro.mp4,null' })\n```\n\nYou can pass any other supported encoding the same way.\n\n### How Cypress validates JSON and JavaScript fixtures\n\nCypress automatically validates your fixtures. If your `.json` or `.js` files contain syntax errors, the test fails with an error that names the fixture and describes the problem.\n\nA `.js` fixture is evaluated as a single JavaScript expression, such as an object literal (`{ name: 'Jane' }`), rather than loaded as a module.\n\n### How Cypress chooses a fixture's encoding\n\nWhen you don't pass an encoding, Cypress reads the file based on its extension:\n\n| Extension | Yields |\n| --- | --- |\n| `.json` | The parsed JSON |\n| `.js` | The evaluated JavaScript expression |\n| `.png`, `.jpg`, `.jpeg`, `.gif`, `.tif`, `.tiff`, `.zip` | A `base64` string |\n| `.html`, `.txt`, `.csv`, and every other extension | A `utf8` string |\n\nTo read a file differently, pass an encoding as the second argument of `cy.fixture()`. You can specify `null` as the encoding to read the file as a [`Cypress.Buffer`](/llm/markdown/api/utilities/buffer.md) instance instead.\n\nThese defaults describe what `cy.fixture()` yields. When you serve a fixture from [`cy.intercept()`](#Serve-a-fixture-directly-from-cyintercept), image and `.zip` fixtures are sent as raw bytes instead of `base64`.\n\n### Sharing fixture data through the `this` context\n\nIf 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.\n\n```\ndescribe('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})\n```\n\n### Loading large files with `cy.fixture()`\n\n#### Why large fixtures can crash or stall Cypress\n\n`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:\n\n*   **Memory pressure**: The complete file must fit in available RAM. Cypress keeps the contents in the fixture cache and yields a separate copy, so each loaded fixture takes up memory more than once. By default, binary files such as images and `.zip` archives are also converted to a `base64` string in the browser, which is about a third larger than the file itself.\n*   **Single-message transfer**: File contents are sent as a single message over the internal socket, so the whole payload is buffered at once.\n\nAs 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.\n\n#### Upload a large file with `.selectFile()` and a path\n\nIf your goal is to simulate a file upload through an `<input type=\"file\">` element, use [`.selectFile()`](/llm/markdown/api/commands/selectfile.md) with a path string rather than loading the fixture first and then setting the input manually:\n\n```\n// ✅ Preferred for file upload simulation\ncy.get('input[type=\"file\"]').selectFile('cypress/fixtures/large.zip')\n```\n\n#### Check a large file in Node.js with `cy.task()`\n\nFor 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 [`cy.task()`](/llm/markdown/api/commands/task.md) to keep the operation in the Node.js context:\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')\nconst { statSync } = require('fs')\n\nmodule.exports = defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath) {\n          const { size } = statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})\n```\n\n```\nimport { defineConfig } from 'cypress'\nimport { statSync } from 'fs'\n\nexport default defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath: string) {\n          const { size } = statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})\n```\n\n```\n// in your test\ncy.task('getFileSize', 'cypress/fixtures/large.zip').then((size) => {\n  expect(size).to.be.greaterThan(0)\n})\n```\n\n### How Cypress caches fixture data\n\nThe first time you load a fixture, Cypress caches its contents, keyed on the path exactly as you wrote it and the encoding. Later `cy.fixture()` calls with the same path and encoding yield the cached contents, even if the file has changed on disk. Because the key is the path as written, `cy.fixture('users')` and `cy.fixture('users.json')` are cached separately, so use one form consistently to read the file only once.\n\nWhen you write to a file inside the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) with [`cy.writeFile()`](/llm/markdown/api/commands/writefile.md), Cypress clears that file from the cache, so the next `cy.fixture()` call reads the new contents:\n\n```\ncy.writeFile('cypress/fixtures/todo.json', { title: 'New data' })\ncy.fixture('todo').its('title').should('eq', 'New data')\n```\n\nCypress doesn't detect changes made any other way, such as from [`cy.task()`](/llm/markdown/api/commands/task.md) or another process. To read a file that changes during your tests, use [`cy.readFile()`](/llm/markdown/api/commands/readfile.md) instead.\n\n#### Fixtures in `cy.intercept()` are read when the route is added\n\nThe `fixture` property of a [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) `StaticResponse` reads the file when Cypress registers the route. Overwriting the file afterwards doesn't change what that route replies with, so the following **will not work**:\n\n```\n// 🚨 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 object read from todo.json\n// when the route was added and NOT { \"title\": \"New data\" }\n```\n\nIn this situation, respond to the network request with the object and add a new intercept when the data changes:\n\n```\n// ✅ 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})\n```\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 1756
    },
    {
      "id": "api/commands/fixture#how-cy-fixture-differs-from-cy-readfile",
      "doc_id": "api/commands/fixture",
      "heading": "How cy.fixture() differs from cy.readFile()",
      "heading_level": 3,
      "content_markdown": "### How `cy.fixture()` differs from `cy.readFile()`\n\nBoth commands read a file from disk, but they answer different questions. `cy.fixture()` answers \"what data should this test start with?\" while [`cy.readFile()`](/llm/markdown/api/commands/readfile.md) answers \"what's in this file right now?\" Use `cy.fixture()` for known data that stays the same during the run, and `cy.readFile()` for files that change or that your app creates. For when to reach for a static `import` or [`cy.task()`](/llm/markdown/api/commands/task.md) instead, see [Choosing how to load test data in Cypress](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Choosing-how-to-load-test-data-in-Cypress).\n\n|  | `cy.fixture()` | `cy.readFile()` |\n| --- | --- | --- |\n| Path is relative to | `fixturesFolder` | The project root |\n| File extension | Optional | Required |\n| Reads from disk | Once per path and encoding, then yields the cached copy | On every call |\n| Retries until assertions pass | No | Yes, reading the file again on each retry |\n| Images by default | A `base64` string | A `utf8` string |\n| Default timeout | `responseTimeout` | `defaultCommandTimeout` |\n| Command Log | Not logged | Logged |\n| Missing file | Always fails | Can be asserted with `.should('not.exist')` |\n",
      "section": "api",
      "anchors": [
        "how-cy-fixture-differs-from-cy-readfile"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 256
    },
    {
      "id": "api/commands/fixture#serve-a-fixture-directly-from-cy-intercept",
      "doc_id": "api/commands/fixture",
      "heading": "Serve a fixture directly from cy.intercept()",
      "heading_level": 3,
      "content_markdown": "### Serve a fixture directly from `cy.intercept()`\n\nFixtures can also be referenced directly without using the `cy.fixture()` command by using the special property `fixture` on the [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) `StaticResponse` object.\n\n```\ncy.intercept('GET', '/users/**', { fixture: 'users' })\n```\n\nThe Command Log's **Routes** panel lists the route as stubbed, and each request it answers appears in the test body without a live server behind it:\n\n`cy.intercept()` serves image and `.zip` fixtures as raw bytes. Other binary files, such as `.mp4` or `.pdf`, are read as `utf8` text by default, which corrupts them. To serve one of those byte for byte, add `null` as the encoding after a comma:\n\n```\ncy.intercept('GET', '/media/intro.mp4', { fixture: 'media/intro.mp4,null' })\n```\n\nYou can pass any other supported encoding the same way.\n",
      "section": "api",
      "anchors": [
        "serve-a-fixture-directly-from-cy-intercept"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 165
    },
    {
      "id": "api/commands/fixture#how-cypress-validates-json-and-javascript-fixtures",
      "doc_id": "api/commands/fixture",
      "heading": "How Cypress validates JSON and JavaScript fixtures",
      "heading_level": 3,
      "content_markdown": "### How Cypress validates JSON and JavaScript fixtures\n\nCypress automatically validates your fixtures. If your `.json` or `.js` files contain syntax errors, the test fails with an error that names the fixture and describes the problem.\n\nA `.js` fixture is evaluated as a single JavaScript expression, such as an object literal (`{ name: 'Jane' }`), rather than loaded as a module.\n",
      "section": "api",
      "anchors": [
        "how-cypress-validates-json-and-javascript-fixtures"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 81
    },
    {
      "id": "api/commands/fixture#how-cypress-chooses-a-fixtures-encoding",
      "doc_id": "api/commands/fixture",
      "heading": "How Cypress chooses a fixture's encoding",
      "heading_level": 3,
      "content_markdown": "### How Cypress chooses a fixture's encoding\n\nWhen you don't pass an encoding, Cypress reads the file based on its extension:\n\n| Extension | Yields |\n| --- | --- |\n| `.json` | The parsed JSON |\n| `.js` | The evaluated JavaScript expression |\n| `.png`, `.jpg`, `.jpeg`, `.gif`, `.tif`, `.tiff`, `.zip` | A `base64` string |\n| `.html`, `.txt`, `.csv`, and every other extension | A `utf8` string |\n\nTo read a file differently, pass an encoding as the second argument of `cy.fixture()`. You can specify `null` as the encoding to read the file as a [`Cypress.Buffer`](/llm/markdown/api/utilities/buffer.md) instance instead.\n\nThese defaults describe what `cy.fixture()` yields. When you serve a fixture from [`cy.intercept()`](#Serve-a-fixture-directly-from-cyintercept), image and `.zip` fixtures are sent as raw bytes instead of `base64`.\n",
      "section": "api",
      "anchors": [
        "how-cypress-chooses-a-fixtures-encoding"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 169
    },
    {
      "id": "api/commands/fixture#sharing-fixture-data-through-the-this-context",
      "doc_id": "api/commands/fixture",
      "heading": "Sharing fixture data through the this context",
      "heading_level": 3,
      "content_markdown": "### Sharing fixture data through the `this` context\n\nIf 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.\n\n```\ndescribe('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})\n```\n",
      "section": "api",
      "anchors": [
        "sharing-fixture-data-through-the-this-context"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 135
    },
    {
      "id": "api/commands/fixture#loading-large-files-with-cy-fixture",
      "doc_id": "api/commands/fixture",
      "heading": "Loading large files with cy.fixture()",
      "heading_level": 3,
      "content_markdown": "### Loading large files with `cy.fixture()`\n\n#### Why large fixtures can crash or stall Cypress\n\n`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:\n\n*   **Memory pressure**: The complete file must fit in available RAM. Cypress keeps the contents in the fixture cache and yields a separate copy, so each loaded fixture takes up memory more than once. By default, binary files such as images and `.zip` archives are also converted to a `base64` string in the browser, which is about a third larger than the file itself.\n*   **Single-message transfer**: File contents are sent as a single message over the internal socket, so the whole payload is buffered at once.\n\nAs 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.\n\n#### Upload a large file with `.selectFile()` and a path\n\nIf your goal is to simulate a file upload through an `<input type=\"file\">` element, use [`.selectFile()`](/llm/markdown/api/commands/selectfile.md) with a path string rather than loading the fixture first and then setting the input manually:\n\n```\n// ✅ Preferred for file upload simulation\ncy.get('input[type=\"file\"]').selectFile('cypress/fixtures/large.zip')\n```\n\n#### Check a large file in Node.js with `cy.task()`\n\nFor 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 [`cy.task()`](/llm/markdown/api/commands/task.md) to keep the operation in the Node.js context:\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')\nconst { statSync } = require('fs')\n\nmodule.exports = defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath) {\n          const { size } = statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})\n```\n\n```\nimport { defineConfig } from 'cypress'\nimport { statSync } from 'fs'\n\nexport default defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath: string) {\n          const { size } = statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})\n```\n\n```\n// in your test\ncy.task('getFileSize', 'cypress/fixtures/large.zip').then((size) => {\n  expect(size).to.be.greaterThan(0)\n})\n```\n",
      "section": "api",
      "anchors": [
        "loading-large-files-with-cy-fixture"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 511
    },
    {
      "id": "api/commands/fixture#why-large-fixtures-can-crash-or-stall-cypress",
      "doc_id": "api/commands/fixture",
      "heading": "Why large fixtures can crash or stall Cypress",
      "heading_level": 4,
      "content_markdown": "#### Why large fixtures can crash or stall Cypress\n\n`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:\n\n*   **Memory pressure**: The complete file must fit in available RAM. Cypress keeps the contents in the fixture cache and yields a separate copy, so each loaded fixture takes up memory more than once. By default, binary files such as images and `.zip` archives are also converted to a `base64` string in the browser, which is about a third larger than the file itself.\n*   **Single-message transfer**: File contents are sent as a single message over the internal socket, so the whole payload is buffered at once.\n\nAs 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.\n",
      "section": "api",
      "anchors": [
        "why-large-fixtures-can-crash-or-stall-cypress"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 240
    },
    {
      "id": "api/commands/fixture#upload-a-large-file-with-selectfile-and-a-path",
      "doc_id": "api/commands/fixture",
      "heading": "Upload a large file with .selectFile() and a path",
      "heading_level": 4,
      "content_markdown": "#### Upload a large file with `.selectFile()` and a path\n\nIf your goal is to simulate a file upload through an `<input type=\"file\">` element, use [`.selectFile()`](/llm/markdown/api/commands/selectfile.md) with a path string rather than loading the fixture first and then setting the input manually:\n\n```\n// ✅ Preferred for file upload simulation\ncy.get('input[type=\"file\"]').selectFile('cypress/fixtures/large.zip')\n```\n",
      "section": "api",
      "anchors": [
        "upload-a-large-file-with-selectfile-and-a-path"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 69
    },
    {
      "id": "api/commands/fixture#check-a-large-file-in-node-js-with-cy-task",
      "doc_id": "api/commands/fixture",
      "heading": "Check a large file in Node.js with cy.task()",
      "heading_level": 4,
      "content_markdown": "#### Check a large file in Node.js with `cy.task()`\n\nFor 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 [`cy.task()`](/llm/markdown/api/commands/task.md) to keep the operation in the Node.js context:\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')\nconst { statSync } = require('fs')\n\nmodule.exports = defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath) {\n          const { size } = statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})\n```\n\n```\nimport { defineConfig } from 'cypress'\nimport { statSync } from 'fs'\n\nexport default defineConfig({\n  e2e: {\n    setupNodeEvents(on, config) {\n      on('task', {\n        getFileSize(filePath: string) {\n          const { size } = statSync(filePath)\n          return size\n        },\n      })\n    },\n  },\n})\n```\n\n```\n// in your test\ncy.task('getFileSize', 'cypress/fixtures/large.zip').then((size) => {\n  expect(size).to.be.greaterThan(0)\n})\n```\n",
      "section": "api",
      "anchors": [
        "check-a-large-file-in-node-js-with-cy-task"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 193
    },
    {
      "id": "api/commands/fixture#how-cypress-caches-fixture-data",
      "doc_id": "api/commands/fixture",
      "heading": "How Cypress caches fixture data",
      "heading_level": 3,
      "content_markdown": "### How Cypress caches fixture data\n\nThe first time you load a fixture, Cypress caches its contents, keyed on the path exactly as you wrote it and the encoding. Later `cy.fixture()` calls with the same path and encoding yield the cached contents, even if the file has changed on disk. Because the key is the path as written, `cy.fixture('users')` and `cy.fixture('users.json')` are cached separately, so use one form consistently to read the file only once.\n\nWhen you write to a file inside the [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) with [`cy.writeFile()`](/llm/markdown/api/commands/writefile.md), Cypress clears that file from the cache, so the next `cy.fixture()` call reads the new contents:\n\n```\ncy.writeFile('cypress/fixtures/todo.json', { title: 'New data' })\ncy.fixture('todo').its('title').should('eq', 'New data')\n```\n\nCypress doesn't detect changes made any other way, such as from [`cy.task()`](/llm/markdown/api/commands/task.md) or another process. To read a file that changes during your tests, use [`cy.readFile()`](/llm/markdown/api/commands/readfile.md) instead.\n\n#### Fixtures in `cy.intercept()` are read when the route is added\n\nThe `fixture` property of a [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) `StaticResponse` reads the file when Cypress registers the route. Overwriting the file afterwards doesn't change what that route replies with, so the following **will not work**:\n\n```\n// 🚨 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 object read from todo.json\n// when the route was added and NOT { \"title\": \"New data\" }\n```\n\nIn this situation, respond to the network request with the object and add a new intercept when the data changes:\n\n```\n// ✅ 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})\n```\n",
      "section": "api",
      "anchors": [
        "how-cypress-caches-fixture-data"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 436
    },
    {
      "id": "api/commands/fixture#fixtures-in-cy-intercept-are-read-when-the-route-is-added",
      "doc_id": "api/commands/fixture",
      "heading": "Fixtures in cy.intercept() are read when the route is added",
      "heading_level": 4,
      "content_markdown": "#### Fixtures in `cy.intercept()` are read when the route is added\n\nThe `fixture` property of a [`cy.intercept()`](/llm/markdown/api/commands/intercept.md) `StaticResponse` reads the file when Cypress registers the route. Overwriting the file afterwards doesn't change what that route replies with, so the following **will not work**:\n\n```\n// 🚨 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 object read from todo.json\n// when the route was added and NOT { \"title\": \"New data\" }\n```\n\nIn this situation, respond to the network request with the object and add a new intercept when the data changes:\n\n```\n// ✅ 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})\n```\n",
      "section": "api",
      "anchors": [
        "fixtures-in-cy-intercept-are-read-when-the-route-is-added"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 249
    },
    {
      "id": "api/commands/fixture#rules",
      "doc_id": "api/commands/fixture",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `cy.fixture()` requires being chained off of `cy`.\n*   `cy.fixture()` requires [`fixturesFolder`](/llm/markdown/app/references/configuration.md#Folders--Files) to be set. It fails if `fixturesFolder` is `false`.\n\n### Assertions\n\n*   `cy.fixture()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).\n\n### Timeouts\n\n*   `cy.fixture()` can time out waiting for the Cypress server to send the fixture. It waits for the `timeout` option, which defaults to [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts).\n*   `cy.fixture()` yields cached contents without waiting on the server, so a cached fixture never times out.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 112
    },
    {
      "id": "api/commands/fixture#timeouts",
      "doc_id": "api/commands/fixture",
      "heading": "Timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts\n\n*   `cy.fixture()` can time out waiting for the Cypress server to send the fixture. It waits for the `timeout` option, which defaults to [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts).\n*   `cy.fixture()` yields cached contents without waiting on the server, so a cached fixture never times out.\n",
      "section": "api",
      "anchors": [
        "timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/fixture#history",
      "doc_id": "api/commands/fixture",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [15.18.0](/llm/markdown/app/references/changelog.md#15-18-0) | An aliased fixture keeps its file name for `.selectFile()` when a later test loads the same fixture. |\n| [15.0.0](/llm/markdown/app/references/changelog.md#15-0-0) | `cy.writeFile()` clears the cache for a fixture it writes. An explicit `encoding` always yields raw file contents. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/fixture#see-also",
      "doc_id": "api/commands/fixture",
      "heading": "See also",
      "heading_level": 2,
      "content_markdown": "## See also\n\n*   [Guide: Variables and Aliases](/llm/markdown/app/core-concepts/variables-and-aliases.md)\n*   [`cy.intercept()`](/llm/markdown/api/commands/intercept.md)\n*   [`cy.readFile()`](/llm/markdown/api/commands/readfile.md) for a similar command without caching and with built-in retryability\n*   [`.selectFile()`](/llm/markdown/api/commands/selectfile.md) for simulating file uploads, including with large files\n*   [`cy.task()`](/llm/markdown/api/commands/task.md) for keeping large file operations in the Node.js context\n",
      "section": "api",
      "anchors": [
        "see-also"
      ],
      "path": "/llm/json/chunked/api/commands/fixture.json",
      "token_estimate": 57
    }
  ]
}