https://cypress.io logo
How can I test Remember Me Functionality without using Session?
g

great-furniture-24480

05/25/2023, 2:09 PM
hi, all have a test scenario where I want to verify the functionality of "Remember Me". In the first test case, I perform a login after checking the "Remember Me" checkbox and then redirect to the dashboard. In the second test case, my intention is to directly access the dashboard without performing another login, relying on the "Remember Me" feature. I expected it to work similarly to a session. However, I don't want to manually create a session for this test, as I have already implemented session management in my other tests. Is there any suggestion on how I can achieve this without creating a session? It's worth noting that the session handling in the browser is done internally by Firebase, and there is no direct access to session cookies. Here is the code: it('should remember login and load dashboard when "Remember Me" is checked', () => { cy.visit('/login'); cy.get('#username').type('your_username'); cy.get('#password').type('your_password'); cy.get('#rememberMe').check(); cy.get('#loginButton').click(); cy.url().should('include', '/dashboard'); }); it('should load dashboard without login if remember me is enabled', () => { cy.visit('/'); cy.url().should("include", "/dashboard"); })
g

gray-kilobyte-89541

05/25/2023, 2:58 PM
instead of the second test, add
cy.reload()
to the first one
g

great-furniture-24480

05/25/2023, 7:05 PM
hi @gray-kilobyte-89541 thank you, I have already tried the reload and it always loads the dashboard even if remember me is not added or checked in the test. Any other Suggestions? Manually the remember me is working fine but not in Cypress.
g

gray-kilobyte-89541

05/25/2023, 7:21 PM
I don't know what the "remember me" is supposed to be. Log out and when you get back it should remember your username? I don't know
e

echoing-tent-95037

05/25/2023, 7:25 PM
The remember me function is stored in a cookie. Cypress wipes that out between each
it
. I don't think theres an easy way for cypress to test this.
You can recall the session before each
it
but that kind of defeats the purpose of what you ware wanting to test.
g

gray-kilobyte-89541

05/25/2023, 8:33 PM
Sure there is. You can either continue in the same test or pass the cookie into the next test and set it before visiting the site
e

echoing-tent-95037

05/25/2023, 9:15 PM
Yeah I guess passing the cookie would work to test that, im just not sure what the min requirements for that remember me to work. If you can strip it down to the basic needs and do a visit in another it with the cookie injected.
g

great-furniture-24480

05/26/2023, 9:19 AM
@gray-kilobyte-89541 the Remember Me is supposed to redirect you to the dashboard if you close the browser or current tab without login in again. @echoing-tent-95037 actually, in my case, there is no cookie in the browser as it is handled by the firebase internally https://firebase.google.com/docs/auth/web/auth-state-persistence.
g

gray-kilobyte-89541

05/26/2023, 2:12 PM
If you provide a small reproducible example, I might consider showing a solution
g

great-furniture-24480

05/28/2023, 1:30 PM
yes sure, here is my test:
it("Login with remember me Checked", () => {
    cy.visit("https://go.beebolt.com/login");
    cy.get("#email").type(email);
    cy.get("#password").type(password);
    cy.get('#rememberMe')
    cy.get("button").contains("Log In").click();
    cy.url().should("include", "/dashboard");
    cy.contains("button.ant-btn", "Dashboard");
  });
What I am doing in the above test is I am checking the remember me checkbox, assuming that It will work as the session works in Cypress. and the next it block will redirect to
/dashboard
without login, it's not working. You suggest using reload but reload works the same for checking or unchecking remember me.
g

gray-kilobyte-89541

05/28/2023, 1:57 PM
Unfortunately I cannot run this since I don’t have the login credentials
g

great-furniture-24480

05/28/2023, 2:45 PM
@gray-kilobyte-89541 DMd you the creds.