How do I stop my test from automatically logging me out when I'm using cypress?

Viewed 33

I'm currently using Cypress to test my application. This particular test I'm talking about needs to fill in a form for a financing flow, divided in 3 different views in my application.

This is my test's code:

describe('finance process logged', () => {
    beforeEach(() => {
      cy.setCookie('token', 'Bearer ' + token)
      cy.intercept('GET', '**/me', { fixture: 'me.json' }).as('getUser')
      cy.intercept('PUT', '**/me', { fixture: 'me.json' }).as('putMe')
      cy.intercept('PATCH', '**/me/gdpr_consents', gdpr_consents).as('patchGDPR')
      cy.intercept('GET', '**/api/v1/payment_methods', {
        fixture: 'purchase-payment-methods.json',
      }).as('getPaymentMethods')
      cy.route({
        method: 'POST',
        url: '**/api/v1/orders',
        status: 200,
        response: {
          uid: '12345',
          status: 'init',
        },
      }).as('newOrder')
      cy.route('GET', '**/api/v1/orders/12345', 'fixture:purchase-order.json').as('getOrder')
      cy.intercept('POST', '**/api/v1/orders/248062de9f2c39e6/payments', 'fixture:financing-payment.json').as('getPayments')
      
    })
    it('finance process ok', () => {
      cy.intercept('POST', '**/api/v1/orders/ca3f258f588ef610/payments', {
        fixture: 'finance-payments-response.json',
      }).as('postPayments')
      cy.intercept('POST', '**/api/v1/transaction_financings/a60ceba307f0dcde/prescorings', {
        fixture: 'finance-update-transaction-response.json',
      }).as('postPrescoring')
      cy.intercept('POST', '**/api/v1/transaction_financings/a60ceba307f0dcde/details', {
        fixture: 'purchase-customer-details.json',
      }).as('postDetails')
      cy.visit('/sportage/sportage-2020-1-6-crdi-isg-6mt-mhev-urban/4c51ed/payment-choose', Cypress.config('VISIT_OPTIONS'))
      cy.getByDataCy('purchase-page').should('be.visible')
      cy.getByDataCy('request-finance').click()
      cy.getByDataCy('financing-page').should('be.visible')
      cy.getByDataCy('start-financing-button').should('be.visible').click()
      cy.getByDataCy('personal-finance-data').should('be.visible')
      cy.getByDataCy('email-input').should('be.visible').should('have.attr', 'disabled')
      fillPersonalData()
      cy.getByDataCy('data-authorization-check').check()
      cy.getByDataCy('button-personal-data-next').click()
      cy.getByDataCy('form-contact-data').should('be.visible')
      fillContactData()
      cy.getByDataCy('button-contact-data-next').click()
      cy.getByDataCy('form-employment-data').should('be.visible')
      fillEmploymentData()
      cy.getByDataCy('button-next-financing').click()
      cy.wait('@postPrescoring')
      cy.wait('@customerOrder')
      cy.wait('@getTariff')
      cy.getByDataCy('finance-requested-page').should('be.visible')
    })

})

The test fails by logging out when it switches tabs in the front (from one form to another), specifically after clicking cy.getByDataCy('button-personal-data-next').click(), and therefore fails in the next step cy.getByDataCy('form-contact-data').should('be.visible').

In my web application, it doesn't log out the client, so I wanted to know how I can prevent it from sing-out the user. Thanks for your help!

1 Answers

You have a couple of cy.route() calls which are deprecated, they should be cy.intercept().

See cy.route()

⚠️ cy.server() and cy.route() are deprecated in Cypress 6.0.0. In a future release, support for cy.server() and cy.route() will be removed. Consider using cy.intercept() instead. See our guide on Migrating cy.route() to cy.intercept()

The cy.route() command was always preceded by cy.server() which you do not have, so probably these commands are doing nothing.

Change them to cy.intercept() and you might fix your problem.

Related