mardi 15 septembre 2020

need to mock POST request in cypress

I'm trying to use cypress to test an Angular app that has a .net core backend. When the app starts, a user has to login with username and password. When the username and password is submitted, it goes to the .net core backend (localhost:5000) which is not running. I need to simulate a login and get back a token. The examples cypress provides the backend server is running. How do I do a mock POST request in cypress?

Here's my cypress code:

const username = 'johndoe';
  const password = 'pass1234';
  cy.get('input[placeholder=Username]').type(username);
  cy.get('input[placeholder=Password]').type(password);
  cy.get('button[type=submit]').click();
  cy.server();
  cy.request({ // this request fails with connection refused since localhost:5000 is not running
    method: 'POST', 
    url: 'http://localhost:5000/Authentication/Login',
    body: {
      username,
      password
    }
  })

Aucun commentaire:

Enregistrer un commentaire