diff --git a/cypress.json b/cypress.json index 5c2eb0b14..27fe65a80 100644 --- a/cypress.json +++ b/cypress.json @@ -9,5 +9,9 @@ "fixturesFolder": false, "baseUrl": "http://localhost:8081", "experimentalSessionAndOrigin": true, - "chromeWebSecurity": false + "chromeWebSecurity": false, + "env": { + "username": "admin-email-here@radar-base.net", + "secret": "secret123" + } } diff --git a/src/test/javascript/e2e/cypress/integration/util/login.ts b/src/test/javascript/e2e/cypress/integration/util/login.ts index 348dc3dbb..84c307c83 100644 --- a/src/test/javascript/e2e/cypress/integration/util/login.ts +++ b/src/test/javascript/e2e/cypress/integration/util/login.ts @@ -1,5 +1,5 @@ export function login() { - cy.login('admin-email-here@radar-base.net', 'secret123'); + cy.login(Cypress.env('username'), Cypress.env('secret')); cy.wait(2000); cy.visit('managementportal/'); } diff --git a/src/test/javascript/e2e/cypress/support/commands.js b/src/test/javascript/e2e/cypress/support/commands.js index d110634aa..e0cc41ea2 100644 --- a/src/test/javascript/e2e/cypress/support/commands.js +++ b/src/test/javascript/e2e/cypress/support/commands.js @@ -23,28 +23,21 @@ Cypress.Commands.add('getCSRFToken', () => { }); Cypress.Commands.add('login', (identifier, password) => { - cy.initiateLoginFlow().then(({flow, csrfToken}) => { - cy.request({ - method: 'POST', - url: IDENTITY_SERVER + `/self-service/login?flow=${flow}`, - body: { - identifier: identifier, - password: password, - csrf_token: csrfToken, - method: 'password' - }, - headers: { - 'Content-Type': 'application/json' - } - }).then((response) => { - const cookies = response.headers['set-cookie'] || []; - cookies.forEach((cookie) => { - const [cookieName, cookieValue] = cookie.split(';')[0].split('='); - cy.setCookie(cookieName, cookieValue); - Cypress.Cookies.defaults({ - preserve: [cookieName, cookieValue] // Ensure relevant cookies are preserved + cy.session([identifier, password], () => { + cy.initiateLoginFlow().then(({flow, csrfToken}) => { + cy.request({ + method: 'POST', + url: IDENTITY_SERVER + `/self-service/login?flow=${flow}`, + body: { + identifier: identifier, + password: password, + csrf_token: csrfToken, + method: 'password' + }, + headers: { + 'Content-Type': 'application/json' + } }); - }); }); }); });