Cypress Cloud – 在测试过程中记录所有网络请求

huangapple go评论55阅读模式
英文:

Cypress Cloud - Recording all network requests during a test

问题

我正在Jenkins上运行Cypress测试,录制这些测试,并在Cypress Cloud平台上查看录制的内容。

我可以查看测试的视频和截图。但是,我想要录制并查看测试期间发送的网络请求,并在Cypress Cloud中查看它们。

这是否可能?如果是的话,如何操作?

我找到的与Cypress Cloud和网络有关的所有信息都是关于拦截特定请求的,而我想要能够展示开发人员整个网络历史,而不是期望一个特定的请求。

谢谢。

英文:

I am running cypress tests on Jenkins,
recording the tests, and viewing the recording on the Cypress Cloud platform.

I can view a video and see a screenshot of the tests. However, I would like to be able to record and view the Network requests sent during the test, and view them in the Cypress Cloud.

Is it possible? If so, how?

All information I found related to the Cyperss Cloud and the network was about intercepting specific requests, and I want to be able to show devs the whole network history without expecting one specific request.

Thanks

答案1

得分: 3

以下是翻译好的部分:

答案在这里如何在Cypress中记录API请求中的特定字段

使用middleware选项进行拦截,以捕获所有内容。

这只是基本设置,您可以调整URL和位置来编写日志。

const intercepts = []

cy.intercept({ url: '*', middleware: true }, (request) => {
  request.continue(response => intercepts.push({request, response}))
})

... 测试

after(() => {
  cy.writeFile('cypress/network/intercepts.json', intercepts)
})
英文:

The answer is here How do I log a specific field in API requests within Cypress.

Use the middleware option to make an intercept that captures everything.

This is bare-bones, you will fine tune things like URL, location to write the log.

const intercepts = []

cy.intercept({ url: '*', middleware: true }, (request) => {
  request.continue(response => intercepts.push({request, response}))
})

... testing

after(() => {
  cy.writeFile('cypress/network/intercepts.json', intercepts)
})

huangapple
  • 本文由 发表于 2023年5月7日 16:37:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192909.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定