Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

javascript - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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))
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...