Keep the page state after user logs in when using cy.session()
See original GitHub issueWhat would you like?
I think we could benefit from a small modification of the cy.session()
command where after the user logs into the application or if the validate()
method is run we could continue from that state in the tests, instead of the page being cleared.
Why is this needed?
When we use cy.session()
and we add a validation for the session like in my case by trying to open a specific page that is only accessible if the user is logged in, then I would have to use:
validate() {
cy.visit('/');
cy.location('pathname', { timeout: 30000 }).should('equals', '/home');
},
and this is the only way I can validate the login for our application. Then after the session we need to again use cy.visit() to navigate to the home page which is again extra time to re-load everything instead of just continuing from the validation or login state… removing the blank page part would be amazing
Other
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top GitHub Comments
+1 for this. We only have one E2E flow in our product (but with certain variations) and our E2E test just wouldn’t make sense if the previous page state isn’t carried over. I’m having to resort putting all the test steps inside an entire
it
block making it less readable and harder to debug incase there’s an errorHowever, I understand that tests, in theory, should have isolated state.
So I’d like to propose maybe we have a
step()
function that would help organize the flow of an E2E test while still being within a single test (it
block) and also display those steps in the Test Runner:However, I know OP’s idea was more for performance sake of reusing the state from previous test and this is more for readability, but I feel this might still work for both use cases.
@devhid This request is to remove the last “Clear Page” step that executed in the
cy.session
command to remove the need to re-visit once a session has been established.What you are describing is disabling test isolation for a set of tests to have better readability and more granular tests for a given point in your application. This actually requested in #22279 and the full extend of this work can be tracked on #22230.