Last active
March 28, 2019 12:10
-
-
Save alanbuxton/c97be71d67364b6861e76c15c7521e79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe ("accessing local storage", function() { | |
function logLocalStorage() { | |
Object.keys(localStorage).forEach(key => { | |
cy.log(key + ": " + localStorage[key]) | |
}) | |
} | |
// if local storage exists it will be logged out here because afterEach happens after each test completes | |
afterEach(() => { | |
cy.log("Logging local storage from _afterEach_:") | |
logLocalStorage() | |
}) | |
it ("visits a web page and clicks a link", function() { | |
cy.visit("https://docs.cypress.io") | |
.get("a").first().click() | |
.then(() => { | |
cy.log("Logging local storage from inside _then_:") | |
logLocalStorage() | |
}) | |
cy.log("Logging local storage from body of test:") | |
logLocalStorage() // Won't log anything as is async | |
}) | |
it ("visits the web page that interactive user was redirected to", function() { | |
cy.visit("https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell").then(() => { | |
cy.log("Logging local storage from inside _then_:") | |
logLocalStorage() | |
}) | |
cy.log("Logging local storage from body of test:") | |
logLocalStorage() // Won't log anything as is async | |
}) | |
it ("visits the original web page but does not interact with page", function() { | |
cy.visit("https://docs.cypress.io").then(() => { | |
/* Won't log anything as there is nothing set. This | |
was initially unexpected behaviour as it looked like | |
the user did have local storage set, but it looks like this is | |
because interactive user gets redirected to a | |
different page that does set local storage | |
*/ | |
cy.log("Logging local storage from inside _then_:") | |
logLocalStorage() | |
}) | |
cy.log("Logging local storage from main body of test:") | |
logLocalStorage() // Won't log anything | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment