bahmutov / bahmutov/cypress-data-session

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

Open
#72 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
67
Forks
11
Avg merge
21h 50m
Merged PRs (30d)
3

Description

### 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](https://user-images.githubusercontent.com/39180176/180313198-53e50406-a468-4ce5-bc3d-c3d475986c86.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the provided Data Session example in a Cypress spec, focusing on the cy.dataSession command used in the before hook and the two test cases. Done means both tests can read the same generated data, including when the session is validated or tests are retried.

Written by the indexing model from the issue text.

Assessment

Tech stack
cypress, javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.