Skip to content

How to Get all IDs for the sessions created using cy.session() #19871

Discussion options

You must be logged in to vote

Some quick digging in the code and this was easy enough to find.

For reference to anyone looking for this, you can get all active sessions by using the function

cy.state('activeSessions')

Afterwards you can easily play with it to retrieve the data that you want:

// get the ids of your sessions using the activeSession keys
Object.keys(cy.state('activeSessions'))

or better

// get the ids of your sessions using the activeSession values - id key
    Object.values(cy.state('activeSessions')).map((sessions) => sessions.id)

or anything else you might be needing.

Note that if you are using Typescript, you will need to @ts-ignore the cy.state() function, as this is not exposed.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by alexniculae
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant