diff --git a/front/cypress/cypress.d.ts b/front/cypress/cypress.d.ts index f61520e3e..0f8cf8ed0 100644 --- a/front/cypress/cypress.d.ts +++ b/front/cypress/cypress.d.ts @@ -2,7 +2,7 @@ declare module 'cypress' { global { namespace Cypress { interface Chainable { - login(): Chainable> + login(): void } } } diff --git a/front/cypress/support/commands.ts b/front/cypress/support/commands.ts index d1abd2e0c..e82d83ce9 100644 --- a/front/cypress/support/commands.ts +++ b/front/cypress/support/commands.ts @@ -1,20 +1,20 @@ // Currently we cannot login purely programmatically, so we need to use the // graphical login until the vue3 branch is merged Cypress.Commands.add('login', () => { - cy.fixture('testuser.json').then((user) => { - const username = user.username - const password = user.password - cy.visit('/login') - cy.wait(1000) - cy.getCookie('csrftoken').then(($cookie) => { - const csrfToken = $cookie?.value + cy.fixture('testuser.json').then(({ username, password }) => { + // We need to request a page that sets the csrf cookie + cy.request('/api/v1/instance/nodeinfo/2.0/') + // Then we can login + cy.visit('/login') + + cy.getCookie('csrftoken').then(($cookie) => { cy.request({ method: 'POST', url: '/api/v1/users/login', form: true, headers: { - 'X-CSRFTOKEN': csrfToken, + 'X-CSRFTOKEN': $cookie?.value, Referer: Cypress.config().baseUrl + '/login' }, body: {