Fixture data for tests
See original GitHub issueCurrent behavior:
const names = ['foo', 'bar', 'baz']
names.forEach(name => {
it(`works for ${name}`, () => {
cy.visit('...')
cy.contains(name)
})
})
Desired behavior:
It would be extremely useful to be able to drive tests out of fixture data. That way if you want to reuse the same data in a different test you don’t need to duplicate it. Possibly like this:
const names = cy.fixture('foo/examples');
names.forEach(name => {
it(`works for ${name}`, () => {
cy.visit('...')
cy.contains(name)
})
})
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:10 (4 by maintainers)
Top Results From Across the Web
ui testing - What are fixtures in programming? - Stack Overflow
Fixtures is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run....
Read more >Test fixture - Wikipedia
A test fixture is an environment used to consistently test some item, device, or piece of software. Test fixtures can be found when...
Read more >Test Fixtures - Software Testing Fundamentals - GitBook
A test fixture is a fixed state of a set of objects used as a baseline for running tests. A test fixture is...
Read more >What Is A JUnit Test Fixture: Tutorial With JUnit 4 Examples
The holistic understanding of the term 'Test Fixture' is a fixed state in a code or a set of fixed steps in a...
Read more >About fixtures — pytest documentation
Fixtures define the steps and data that constitute the arrange phase of a test (see Anatomy of a test). In pytest, they are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To recap for posterity: There are three reliable ways to do this:
The examples below expect the fixture file to contain an array.
.fixture()
inside anit
The Cypress chain in the example cannot be executed outside anit
block..fixture
inside abefore
orbeforeEach
The Cypress chain in the example cannot be executed outside abefore
/beforeEach
block.Using
require
Note that you can use this method to dynamically generate tests by swapping lines 4 and 5. If you don’t know what this means I suggest you simply try it to see what happens.Does anyone have anything to add?
const someObject = require(“…/fixtures/URLParameterSignUpConfigs/URLParameterSignUpConfigs.json”);
describe(‘URL Parameter Sign Up Test’, () => { it(‘Navigate to URL with Query String’, () => { cy.log(someObject.keyContactName); }); });
Any idea why would that be?