Cypress Post Request Fails when trying AutoLogin

I am trying to make POST request in Cypress in order to perform auto login and redirect to dashboard page.
Here is the

Error

enter image description here

The Code I have added to perform auto login is

Cypress.Commands.add('autologin', () => {
  cy.clearCookies();
  let options = {
    method: 'POST',
    url: 'https://admin-demo.nopcommerce.com/login?returnurl=%2Fadmin%2F',
    headers: {
      'authority': 'admin-demo.nopcommerce.com',
      'Content-Type': 'application/x-www-form-urlencoded',
      'origin': 'https://admin-demo.nopcommerce.com',
    },
    body: {
      Email: '[email protected]',
      Password: 'admin',
      __RequestVerificationToken:
        'CfDJ8EoKK8bdbeVGtbyUmFkZjVXayQ00hwk5B6a1cPRgR3HvKKdGXLUNrX2hLPzPqPWV-RDY0zU-qaOalPnt9-fPC7xnshZqx1MMB_2aKitiCzSmm4CstnsQSi3YfrYGFzMVhck6tI02IznyqRUto2akvAA',
      RememberMe: false,
    },
  };
  cy.request(options).then(response => {
    console.log(response);
  });
});
Cypress.Commands.add('login', () => {
  cy.autologin();
  cy.visit('https://admin-demo.nopcommerce.com');
  cy.get('#nopSideBarPusher').should('be.visible').click();
  cy.get('#nopSideBarPusher').should('be.visible').click();
  cy.clearCookies();
  cy.get('.navbar-collapse .nav-link')
    .eq(1)
    .then(val => {
      cy.get(val).click();
    });
});

Source: Ask Javascript Questions

LEAVE A COMMENT