CYPRESS-XHR持续时间不再由cy.intercept()捕获 [英] CYPRESS - XHR duration no longer captured with cy.intercept()
问题描述
Cypress将在使用 cy.intercept()时弃用 cy.route()和 cy.server() >
这是我的旧代码,它将捕获XHR时间并输出
cy.server()cy.route('POST',api_URL_Live).as('CONS');cy.wait('@ CONS').then((xhr)=> {CONSTime = Number(JSON.stringify(xhr.duration));});
这非常有效,并且可以将持续时间保存到文件中
不再捕获持续时间的新代码
cy.intercept('POST',api_URL_Live).as('CONS');cy.wait('@ CONS').then((xhr)=> {CONSTime = Number(JSON.stringify(xhr.duration));});
有人知道为什么该功能不再起作用,需要任何帮助吗?
cy.intercept的API
和 cy.route
有一些重叠,但是不一样.
持续时间
是 cy.route
的一个未记录的属性,但是它确实可以工作,尽管它不受正式支持.
因为它没有文档记录,并且很少在 cy.route
中使用,所以在 cy.intercept
中不考虑将其实现.
您仍然可以使用 cy.route
测量请求的持续时间-不会删除 cy.route
,从而使代码损坏.一旦 cy.intercept
对于大多数常见用例足够稳定,它将很可能移至插件.
如果您想对 cy.intercept
做同样的事情,则可以使用回调进行测量:
cy.intercept('POST',url,(req)=> {const startTime = Date.now()req.reply(res => {//测量收到请求和收到响应之间的时间totalTime = Date.now()-startTime})})
有一个开放功能请求,用于向 cy.intercept
添加计时数据: https://github.com/cypress-io/cypress/issues/15969
Cypress are about to deprecate cy.route() and cy.server() in use of cy.intercept()
Here is my OLD Code, that would capture XHR time and output
cy.server()
cy.route('POST', api_URL_Live).as('CONS');
cy.wait('@CONS').then((xhr) => {
CONSTime = Number(JSON.stringify(xhr.duration));
});
This worked perfectly and would out put the duration to a file
New code that no longer captures duration
cy.intercept('POST', api_URL_Live).as('CONS');
cy.wait('@CONS').then((xhr) => {
CONSTime = Number(JSON.stringify(xhr.duration));
});
Does anyone know why this functionality no longer works, any help appreciated?
The APIs of cy.intercept
and cy.route
have some overlap, but are not the same.
duration
is an undocumented property of cy.route
, but it does work, although it is not formally supported.
Because it was undocumented and rarely used in cy.route
, it was not considered for implementation in cy.intercept
.
You can still measure a request's duration using cy.route
- cy.route
is not going to be deleted, leaving your code broken. It will most likely be moved to a plugin once cy.intercept
is stable enough for most common use cases.
If you would like to do the same with cy.intercept
, you can measure by using callbacks:
cy.intercept('POST', url, (req) => {
const startTime = Date.now()
req.reply(res => {
// measure the time between request received and response received
totalTime = Date.now() - startTime
})
})
There is an open feature request to add timing data to cy.intercept
: https://github.com/cypress-io/cypress/issues/15969
这篇关于CYPRESS-XHR持续时间不再由cy.intercept()捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!