我有一個攔截器正在獲取GET對發生四次的端點的請求。
cy.intercept(`endpoint/data*`).as(
'texasCounties'
);
這發生了四次在這里看到。
在最后一個請求中對我來說唯一重要的是,但是,當我等待回應時,它只與第一個請求掛鉤,我無法訪問第四個請求的回應正文。這是我到目前為止所擁有的
cy.wait('@texasCounties').then((interceptor) => {
const res = interceptor.response.body
cy.log(res) //only print object for the first request but I need the fourth
})
我試圖cy.wait('@texasCounties').eq(3)獲得第四個請求,但這不起作用。
有誰知道如何做到這一點?
uj5u.com熱心網友回復:
如果您只需要最后一次通話,您可以在通話之前移動您的攔截。
通過您的嘗試,您已經接近答案。您必須使用.get('@alias')獲取所有攔截的請求并使用.its(). 這就是它的樣子。
// intercept and other test code
cy.get('@texasCounties.all') // this will get all four intercepted requests
.then(console.log) // if you want to log
.should('have.length', 4) // you can make assertions
.its(3) // to access the fourth request
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/476720.html
標籤:javascript 反应 柏
