question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress session validation failure results in a 'existingSession.setup is not a function' error

See original GitHub issue

Current behavior

While using the new experimental feature sessions in cypress 8.2.0, adding a session validation routine does not seem to work correctly. Specifically, when a session exists, but the validation routine returns false, an error is thrown saying that the setup function does not exist.

Here is a sample block of code that can reproduce this issue: Screenshot from 2021-08-19 09-53-14

When running this for the first time: Screenshot from 2021-08-19 09-52-29

When re-running this test: Screenshot from 2021-08-19 09-52-45

Desired behavior

Cypress should fail the validation, and re-run the setup function as specified in the docs. For some reason, the current code somehow loses the setup function when validation fails.

Test code to reproduce

  it('fails the session setup on the second run', () => {
    var validateFlag = false
    cy.session('test', () => {
      validateFlag = true
      cy.log('setup')
    },
    {
      validate() {
        cy.log('validate')
        if (validateFlag) {
          return true
        }
        else {
          return false
        }
      },
    })
  });

Cypress Version

8.2.0

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
eLarocquecommented, Jan 12, 2022

Same issue here. Providing the validate function is useless until this is fixed. I know this is an experimental feature (and a great one at that!) but would love this issue prioritized 😃 Thanks!

6reactions
alexniculaecommented, Oct 20, 2021

Hello @Bkucera - is the change propose by Bahmutov, or another fix for this issue, planned to be introduce in an upcoming release? Thank you, Alex

Read more comments on GitHub >

github_iconTop Results From Across the Web

session - Cypress Documentation
If validation fails after restoring a session, setup will re-run. ... Run any Cypress command that fails if the user is not logged...
Read more >
Test fail when using Cypress session - Stack Overflow
After I execute the code, I always got an error: (uncaught exception) TypeError: Cannot read properties of null (reading 'style') TypeError The ...
Read more >
End-to-End Testing with Cypress and Auth0
Learn how to programmatically authenticate against Auth0 in your Cypress tests in a manner that adheres to both Cypress and Auth0 best practices....
Read more >
Flexible Cypress Data Setup And Validation - Gleb Bahmutov
Setting up, caching, and re-creating the test data using cypress-data-session plugin. This post will introduce you to a very powerful way of ...
Read more >
Dependents (89) - @okta/okta-auth-js - npm
The Okta Auth SDK. Latest version: 7.0.1, last published: 10 days ago. Start using @okta/okta-auth-js in your project by running `npm i ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found