-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cy.session: Support IndexedDB #18350
Comments
+1 👍 |
1 similar comment
+1 👍 |
Any word on this? Firebase uses indexedDB for session storage. So |
+1 Has anyone tried manually saving and restoring IndexedDB using localforage or similar? I also am having challenge because of Firebase. Would it be possible to coordinate efforts and put together a workaround? I'd love to help. |
Facing a similar issue here and would love to work on a solution and publish it back here. I haven't been able to figure out how |
I found a workaround to circumvent this: Cypress.Commands.add(
'exportIDB',
(dbName) =>
new Cypress.Promise(async (resolve) => {
indexedDB.open(dbName).onsuccess = async (event) => {
const db = (event.target as IDBOpenDBRequest).result
const json = await exportToJson(db)
console.log(json)
localStorage.setItem(dbName, json)
resolve(json)
}
})
)
Cypress.Commands.add(
'importIDB',
(dbName) =>
new Cypress.Promise(async (resolve) => {
const json = localStorage.getItem(dbName)
console.log(json)
if (!json) {
resolve()
return
}
indexedDB.open(dbName).onsuccess = async (event) => {
const db = (event.target as IDBOpenDBRequest).result
await clearDatabase(db)
await importFromJson(db, json.toString())
resolve()
}
})
)
Cypress.Commands.add('fn', () => {
cy.session(
() => {
/*regular session setup */
// export the data to localStorage, as session does not persist the IndexedDB
cy.exportIDB()
},
{
validate: () => {
// import the data from localstorage to the indexedDB
cy.importIDB()
/* validate extra stuff */
},
// if you want this session to be cached only for a single file, remove the following option
cacheAcrossSpecs: true,
}
)
}) |
This is brilliant! Will give it a try. Thanks for sharing! |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
Still needed |
Hi, I am in a JavaScript project and the workaround proposed by @nicolassanmar doesn't work for me. When |
@jennifer-shehane @mike-plummer could you please see if this can be added to the roadmap? It seems that cy.session() does not handle IndexedDB, this is used by Firebase for session storage. Therefore cy.session() does not work to cache a logged-in session in a Firebase app. I know there's a viable workaround, but it seems to me to be a small fix for a big win... |
Same issue here as well. Good to have a fix than a work around. |
Same issue. The workaround didn't work for me. 🤷♂️ The application stayed logged out and the session would need to be recreated every time. |
What would you like?
The new
cy.session
API currently doesn't do anything with indexeddb. Is that likely to be supported in the future?Why is this needed?
I'm testing an app that stores significants amounts of data in indexeddb to support offline use.
In the app, when a users choses to "Go Offline," data is downloaded from the server to indexeddb. I would like to cache/restore that data with
cy.session
so that each tests for offline functionality doesn't have to re-download that data.Other
No response
The text was updated successfully, but these errors were encountered: