Skip to content

Conversation

@azul
Copy link
Contributor

@azul azul commented Dec 30, 2021

Use the new session feature to create and reuse sessions:
https://docs.cypress.io/api/commands/session

The first time login with a given name is called
the steps described in the login function are performed
and cookies and localstorage are cached.

The next time login is called with the same name
cookies and localStorage are restored and used again.

This allows us to keep fast test runs
while still separating the tests more cleanly.

The old logout command was broken because of the way
we used Cypress.Cookies.defaults({ preserve }) before:

Cypress runs all the cy.* commands during initialization
and builds a list of commands that are then executed during the tests.
However Cypress.Cookies.defaults is evaluated when preparing the list
not while performing the actual steps.

Signed-off-by: Azul [email protected]

  • Target version: master

Use the new session feature to create and reuse sessions:
https://docs.cypress.io/api/commands/session

The first time `login` with a given name is called
the steps described in the login function are performed
and cookies and localstorage are cached.

The next time `login` is called with the same name
cookies and localStorage are restored and used again.

This allows us to keep fast test runs
while still separating the tests more cleanly.

The old logout command was broken because of the way
we used `Cypress.Cookies.defaults({ preserve })` before:

Cypress runs all the `cy.*` commands during initialization
and builds a list of commands that are then executed during the tests.
However `Cypress.Cookies.defaults` is evaluated when preparing the list
not while performing the actual steps.

Signed-off-by: Azul <[email protected]>
@azul azul force-pushed the cypress/login-with-sessions branch 2 times, most recently from fd51a2a to 448df55 Compare December 30, 2021 15:13
Open the test.md file once and then check all the things.

Signed-off-by: Azul <[email protected]>
@azul azul force-pushed the cypress/login-with-sessions branch from 448df55 to 02cfe27 Compare December 30, 2021 15:15
@azul azul requested a review from juliusknorr January 3, 2022 07:48
@azul
Copy link
Contributor Author

azul commented Jan 3, 2022

I think this is the cleanest way and would be a good basis for implementing more complex tests with cypress.

However since it's only available since 8.2.0 we can only backport it to stable23 (cypress 8.6.0) but not to stable22 (cypress 7.5.0) - unless we update cypress there.

I'm currently working on #2020 and i want to prevent regressions like this in the future. Cypress tests seem to be the best way to ensure we don't break things over and over again to me. However if they are very destinct for old branches and the current one backporting the tests adds yet more maintainance overhead.

@juliusknorr juliusknorr added 3. to review tests If you write them we ♥ you labels Jan 3, 2022
@juliusknorr juliusknorr added this to the Nextcloud 24 milestone Jan 3, 2022
@juliusknorr
Copy link
Member

Very nice, that is a lot cleaner 👏

I think we could also just bump cypress on the stable branches

Copy link
Member

@mejo- mejo- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, indeed much cleaner than before :)

@juliusknorr juliusknorr merged commit d325c0a into master Jan 3, 2022
@juliusknorr juliusknorr deleted the cypress/login-with-sessions branch January 3, 2022 10:44
@juliusknorr
Copy link
Member

/backport to stable23

@azul
Copy link
Contributor Author

azul commented Jan 5, 2022

/backport to stable22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review tests If you write them we ♥ you

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants