Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

By using cy.dataSession in the 'before' hook, I should be able to access the data in all test cases of the spec #72

Open
mateustalles opened this issue Jul 21, 2022 · 0 comments

Comments

@mateustalles
Copy link

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.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant