diff --git a/login.js b/login.js index d40380a..a000b07 100644 --- a/login.js +++ b/login.js @@ -3,32 +3,33 @@ // cy.login('username', 'password'); // login as a specific user. Cypress.Commands.add('login', (usernameParam = '', password = '') => { - cy.logout() - cy.visit('/user/login') - let username = ''; - let default_user = false; - if (usernameParam === '' && password === '') { - username = 'cypress'; - default_user = true; - } - else { - username = usernameParam; - } + cy.logout(); + cy.visit("/user/login"); + let username = ""; + let default_user = false; + if (usernameParam === "" && password === "") { + username = "cypress"; + default_user = true; + } else { + username = usernameParam; + } - if (default_user) { - cy.get('form.user-login-form #edit-name').type(username); - cy.get('form.user-login-form #edit-pass').type('cypress'); - } - else { - cy.get('form.user-login-form #edit-name').type(username); - cy.get('form.user-login-form #edit-pass').type(password); - } + if (default_user) { + cy.get("form.user-login-form #edit-name").type(username); + cy.get("form.user-login-form #edit-pass").type("cypress"); + } else { + cy.get("form.user-login-form #edit-name").type(username); + cy.get("form.user-login-form #edit-pass").type(password); + } - // Login. - cy.get('form.user-login-form .form-submit').click(); - cy.wait(500) // Wait for the UI to catch up. + // Login. + cy.get("form.user-login-form .form-submit").click(); + cy.wait(500); // Wait for the UI to catch up. - // Check user page loads. - cy.get('main').contains(username) - cy.get('main').contains('Member for') + // Check user session cookie is set after logging in. + cy.getCookies().then((cookies) => { + // Search for cookie.name and value contains SESS. + const sessionCookie = cookies.find((cookie) => cookie.name.includes("SESS")); + expect(sessionCookie).to.exist; + }); })