Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsPass the fixture path—or a variable containing that path—to cy.fixture(). Cypress resolves it relative to the configured fixturesFolder, which defaults to cypress/fixtures. Use the value yielded by cy.fixture() inside .then() or a later Cypress command. If you need fixture data to create separate test cases before a test runs, use a static import instead: Cypress registers describe() and it() synchronously when it loads the spec.
Pass a variable to cy.fixture()
Store the fixture path in a string variable and pass that variable directly to cy.fixture(). The command yields the parsed fixture data, so consume it in the callback rather than expecting the call to return the data immediately.
const fixtureName = 'users'
describe('user fixture', () => {
it('loads the selected fixture', () => {
cy.fixture(fixtureName).then((users) => {
cy.log(`Loaded ${users.length} users`)
expect(users).to.be.an('array')
})
})
})
With the default fixtures folder, this example looks for cypress/fixtures/users. Cypress can resolve the extension when it is omitted; if the matching supported file is users.json, the shorter path works. You can also write 'users.json' explicitly. For a nested fixture, pass a path such as 'users/admin.json'. The path is relative to the configured fixtures folder, not to the spec file. See the Cypress fixture API for path, encoding, and extension behavior.
Choose the path at runtime
A variable is useful when a test chooses its input based on a scenario, environment setting, or a value computed during the test. The important detail is that the string must be available when the fixture command is enqueued. For example:
#1 Best Overall
it('loads a fixture selected for the current scenario', () => {
const scenario = 'admin'
const fixtureName = `users/${scenario}.json`
cy.fixture(fixtureName).then((user) => {
expect(user.role).to.equal('admin')
})
})
Use a path you control or validate before building it from external input. A misspelled name or path that does not identify a fixture will fail when Cypress attempts to load it; constructing the string dynamically does not change how Cypress resolves the path.
Use the yielded fixture data in Cypress’s command chain
Cypress commands are queued and run asynchronously. Do not assign the result of cy.fixture() to an ordinary variable and then read that variable on the next line as if the fixture had loaded synchronously. Instead, use the yielded value in .then(), or pass it into another Cypress command from that callback.
Use the fixture in an assertion or browser action
it('checks a user shown in the page', () => {
cy.fixture('users/admin.json').then((user) => {
cy.visit('/users')
cy.get('[data-cy="user-name"]').should('have.text', user.name)
})
})
Commands added inside the callback are still Cypress commands and join the Cypress command queue. Keep code that depends on the loaded fixture inside the callback or in a subsequent chain that receives the value. This makes the order of operations explicit: load the fixture, then use its contents.
Use a loaded fixture to stub an API request
If you need to transform or inspect the response data before stubbing a request, load the fixture and pass the yielded object to cy.intercept():
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
const fixtureName = 'items.json'
it('stubs the items request with fixture data', () => {
cy.fixture(fixtureName).then((items) => {
cy.intercept('GET', '/api/items', items).as('getItems')
})
cy.visit('/items')
cy.wait('@getItems')
})
For a fixed response that does not need a separate load or transformation, use the fixture option directly in the intercept route handler:
it('serves a fixed fixture response', () => {
cy.intercept('GET', '/api/items', { fixture: 'items.json' }).as('getItems')
cy.visit('/items')
cy.wait('@getItems')
})
The direct form is less code when the response is simply a fixture file. The callback form is useful when the test needs the loaded data for additional setup or assertions. Cypress documents fixture responses in its network requests guide.
Runtime fixture loading is not test generation
There are two different meanings of “use a fixture dynamically.” A test can choose which fixture to load while it runs. But a fixture loaded with cy.fixture() cannot decide which it() blocks exist in that same run: Cypress builds the test structure before it executes those commands.
For data-driven test definitions, import JSON statically
If each record in a JSON file should become a separate test, import that file at the top of the spec and register the tests synchronously:
Rank #3
import scenarios from '../fixtures/scenarios.json'
describe('scenario pages', () => {
scenarios.forEach((scenario) => {
it(scenario.title, () => {
cy.visit(scenario.path)
})
})
})
Adjust the relative import path to match your spec and project structure. This works because the bundler makes the imported JSON available while the spec is evaluated. Cypress’s test organization guide explains the timing constraint directly: “The describe()/it() structure is built synchronously when the spec loads.”
By contrast, cy.fixture() is a Cypress command that runs within a test. It can supply values to test steps, but it runs too late to register new test blocks. If you need a collection of test cases, make the records available synchronously—typically with a static JSON import—rather than trying to load them with cy.fixture() and then call it() inside its callback.
Choose the file-loading method for the job
| Need | Use | Reason |
|---|---|---|
| Stable test input available during a test | cy.fixture() |
Loads controlled fixture data for use in the Cypress command chain. |
| JSON records needed to register tests as the spec loads | Static import or require |
Makes the data available synchronously when the spec is evaluated. |
| A file that can change during the run or is generated by the application | cy.readFile() |
Reads the current file contents rather than relying on the fixture cache. |
| A large file or file work that belongs in Node.js | cy.task() |
Moves Node-side work out of the browser test runner. |
Fixtures are cached: changing a fixture file outside the test does not make Cypress refresh the contents it already loaded. If the test needs the current contents of a mutable or generated file, use cy.readFile(). For large files or operations that need Node.js, use cy.task(). Cypress’s fixture API and test-data guidance describe these distinctions.
Read a fixture as raw text
JSON fixture files are parsed as JSON by default. If a test needs the file contents as a string—for example, to inspect or compare the raw text—specify an encoding:
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
cy.fixture('payload.json', 'utf8').then((rawText) => {
expect(rawText).to.be.a('string')
expect(rawText).to.include('"status"')
})
Choose this only when the test needs the serialized text. If you want to assert on JSON properties, use the default parsed object instead. The fixture API lists supported encodings and explains how Cypress handles extensions.
Troubleshoot fixture-string failures
“Fixture file not found”
- Check the configured folder. The default is
cypress/fixtures, but a project can configure anotherfixturesFolder. The fixture path is relative to that folder. - Check spelling, capitalization, and nesting. Confirm that the actual file path matches the string, including any subfolder such as
users/admin.json. - Try the explicit extension. Cypress can resolve an omitted extension when it matches a supported file, but writing
users.jsonremoves ambiguity if multiple files could match.
The fixture variable is empty or has the wrong value
- Inspect where it is set. Make sure the string is assigned before Cypress queues
cy.fixture(fixtureName). - Do not read the fixture result synchronously. Put dependent assertions and commands in
.then()or an appropriate later Cypress chain; the fixture command does not return the contents immediately to ordinary JavaScript. - Check how the string is constructed. Log or assert the path string before loading it if it depends on a scenario or other test value.
The test does not create one case per fixture record
That is a timing mismatch, not a path problem. cy.fixture() executes inside a test, after Cypress has loaded the spec and registered its test structure. Import the JSON synchronously and loop over its records while defining the tests. See the Cypress test organization guide.
Changes to a fixture file are not visible
Cypress caches fixture contents, so external edits made during the run are not reflected by another fixture load. For a file whose contents change as the test runs, use cy.readFile() instead; for large or Node.js-specific work, consider cy.task().
Or skip the browser setup
If you also need a website screenshot for debugging or a test artifact, ScreenshotNeo is a separate screenshot API—not a replacement for Cypress fixtures. A single GET request can return a screenshot or PDF. See the ScreenshotNeo API documentation.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallBest Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Before capture, ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents using Claude, Cursor, or another MCP client. The free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000.
Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Can I pass a fixture path through a Cypress environment variable?
Yes, once the value is available in the test, pass the resulting string to cy.fixture(); it remains a fixture path relative to fixturesFolder.
Can I use a fixture string with a custom fixtures folder?
Yes. Configure the folder in Cypress and pass a path relative to that configured folder, rather than adding the folder’s path again.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

