Search code examples
javascriptautomated-testsmocha.jscypressmochawesome

Is there any way to save a full XHR payload in a cypress run?


We have our cypress suite working fine locally in every machine, environment, location. We've configured it to work with a Bitbucket pipeline but there is a specific step that consistently fails because of the API call it makes. This API call is made to an external service and we are adding params in the payload that are dynamically built with the request.

Our suspicion is that there are some of these params that are not built correctly when running it from the pipeline (may be related to location, agent, etc) because we are getting "Unauthorized".

So the issue is that we don't have any way to debug this API call from the pipeline and it is the only place where it fails.

So, do you have any suggestions on how to save the XHR Payload in a step in Cypress?

  • Store it in a mocha report.
  • Send it via email.
  • Maybe add it to a log.
  • Save it as an artifact. I'm sorry I'm just clueless how to approach this as I'm not an expert in neither cypress nor bitbucket pipelines.

More specifically, I need to debug this call:

enter image description here


Solution

  • As I understand, your external API call URL is known, right? If so, I would suggest for debugging purpose to route this call, then display it out in the cypress running logs, so you will be able to compare the request payloads:

    cy.route({ method: 'POST', url: `/ps/users`}).as('routedRequest');
    
    ... 
    
    cy.get('@routedRequest').then((xhr) => {
        cy.log(JSON.stringify(xhr.request))
    });