Skip to content

Commit ae107df

Browse files
Cypress command for local storage
1 parent bf3e335 commit ae107df

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//https://github.com/cypress-io/cypress/issues/461#issuecomment-325402086
2+
const command = () => {
3+
let LOCAL_STORAGE_MEMORY = {}
4+
Cypress.Commands.add("saveLocalStorage", () => {
5+
Object.keys(localStorage).forEach((key) => {
6+
LOCAL_STORAGE_MEMORY[key] = localStorage[key]
7+
})
8+
})
9+
Cypress.Commands.add("restoreLocalStorage", () => {
10+
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
11+
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key])
12+
})
13+
})
14+
}
15+
export default command

0 commit comments

Comments
 (0)