1

I have written cypres test suite for a symfony application .MOst of the Times it runs into csrf token error on form submissions.Each of my forms has a form token something like this <input type="hidden" id="phone_number_submit_pin__token" name="phone_number_submit_pin[_token]" value="..." /></form>

test I have written :-

  beforeEach(() => Cypress.Cookies.preserveOnce('PHPSESSID'));
  const payload = {
    emailLead: `test${Cypress._.random(1000, 99999)}@123.com`,
    mobileNumber: `077890${Cypress._.random(10000, 99999)}`,
    apiId: Cypress.env('id'),
    apiToken: Cypress.env('key'),
  };
it('Send verification pin', () => {
    cy.contains('Send pin').click();
    cy.location('pathname').should('eq', '/phone-number/verify');
  });

  it('Verifies phone number', () => {
    cy.contains('Submit pin').click();
    cy.location('pathname').should('eq', '/private-area/borrower');
  });
});

I have tried to preserve the PHP session id but still it does not work

I am getting error like this which stops the execution of test "The CSRF token is invalid. Please try to resubmit the form."

expected /phone-number/verify to equal **/private-area/borrower**

0 Answers0