lundi 23 décembre 2019

Testcafe multiple requests to endpoint synchronously not working

Currently I am setting up testcafe and have hit a hurdle when making a request to the same endpoint.

This is an authentication request. The steps are currently:

  1. Initial request is sent to server which responds with a body. This is awaited
  2. Once step is retrieved from step 1 this is mutated and sent back to the server.
  3. We then the same endpoint and pass in the body generated in step 2

But I am having issues in the testcafe tests as it always using the first request and returns that twice.

I have referred to this issue on testcafe https://github.com/DevExpress/testcafe/issues/2477 however this did not work.

const mock = (mockResponse, status) => {

  return RequestMock()
      .onRequestTo(/\/apitest\/authenticate\)
      .respond(mockResponse, status, {
        "Access-Control-Allow-Origin": "http://localhost:3000",
        "Access-Control-Allow-Credentials": "true"
      });
};


const mock1 = mock(RESPONSE1, 200);
const mock2 = mock(RESPONSE2, 200);

test.requestHooks(mock1)(
  "Should redirect to error if user has been suspended after submitting",
  async t => {
    const usernameInput = Selector("#username");
    const mobileDigitOne = Selector("#mobile-digit-0");
    const mobileDigitTwo = Selector("#mobile-digit-1");
    const mobileDigitThree = Selector("#mobile-digit-2");
    const submitButton = Selector("#submit-button");

    await t
      .typeText(usernameInput, "username123456")
      .click(digits)
      .typeText(digits, "123456")
      .click(submitButton);

    await t.removeRequestHooks(mock1);

    await t.addRequestHooks(mock2);

Any ideas on how to request same endpoint multiple times?

Aucun commentaire:

Enregistrer un commentaire