cypress-data-session
cypress-data-session copied to clipboard
By using cy.dataSession in the 'before' hook, I should be able to access the data in all test cases of the spec
By using cy.dataSession in the 'before' hook, I should be able to access the data in all test cases of the spec.
Description
If a user wants to use a data session to create one set o data valid throughout the test, it should run only once, and not twice eg if the test retries, and it should be usable between test cases in the same spec. However, when we set the code, it's actually only valid for the first test case, and not for the rest.
Reproductible example:
context('Data Session tests', { tags: ['@customized'] }, () => {
before(() =>
cy.dataSession({
name: 'dataSessionTest',
setup: () => cy.wrap({ data: 'test' }).then(data => data),
validate: true,
})
)
it('test 1 - can read data generated at Data Session', function () {
const { data } = this.dataSessionTest
expect(data).to.equal('test')
})
it('test 2 - should still read data generated at Data Session', function () {
const { data } = this.dataSessionTest
expect(data).to.equal('test')
})
})
Expected Results
Both tests will pass because they have the same assertions and access the same data from the hook
Actual Result
The second test will fail because it can't access the data generated anymore.