Localstorage cleared after first test
Closed this issue · 2 comments
- Operating System: macOs 10.13.3
- Cypress Version: 2.0.2
- Browser Version: 64.0.3282.167 (Official Build) (64-bit)
Is this a Feature or Bug?
BUG
Current behavior:
It clears localstorage after first it()
.
Desired behavior:
It keeps localstorage throughout a describe block.
How to reproduce:
Set localstorage describe() with before(), have 2 it() use localstorage in first and then check second...
Test code:
describe('Quotes', function() {
before(() => {
cy.visit('/', {
onBeforeLoad: win => {
// and before the page finishes loading
// set the id_token in local storage
win.localStorage.setItem('token', tokens.TOKEN);
}
});
});
context('Create Quote', () => {
it('creates a quote', () => {
cy.visit('/sales/pipelines');
cy
.get(sel('pipeline-link'))
.first()
.click();
// token in localstorage is available here
cy.get(sel('create-kv-button')).click();
cy.contains('Raummanagement');
});
});
context('Start Tab', () => {
it('sets a start date', () => {
cy.get(sel('Startdatum-input')).click();
// token in localstorage is NOT available here
cy
.get('.react-datepicker__day')
.first()
.click();
});
});
});
Additional Info (images, stack traces, etc)
I know that this is not best practice to depend on test states for your next tests but in this case its neccesary. I could use beforeEach()
to set the token but thats not very efficient...
Yeah this isn't a bug it's a feature. We always clear up state between tests, but we do a terrible job communicating it - and that other issue tracks all the things we need to do to fix this.
This is really high up on our radar and will be fixed relatively soon. At the moment you could just cache the token in spec itself in the before
hook, and then restore it in the beforeEach
by setting localStorage directly.
Closing this for now, but referencing it in the other issue.