我想測驗網路請求并使用賽普拉斯斷言請求的資料。
cy.intercept('POST', '*service=jobsSearch*').as('ajaxRequest')
cy.get(selectors.dataComponent('jobs')).find('button').click()
cy.wait('@ajaxRequest')
cy.get('@ajaxRequest').its('request.body').should('contain', 'jobApprenticeshipType=stelle')
cy.get('@ajaxRequest').its('results.body').should('contain', 'mailAlertSearchTerm=Handwerk & Produktion')
我可以到達'request.body'并斷言'jobApprenticeshipType=stelle'. 但是,我無法results.body斷言'mailAlertSearchTerm=Handwerk & Produktion'。這是結果的螢屏截圖:

uj5u.com熱心網友回復:
回應有一個鍵 ofresponse和 not results。我的猜測是你的反應看起來像......
{
"results": {
...
"mailAlertSearchTerm": "foo"
...
}
}
在這種情況下,您希望通過以下方式參考它:
cy.get('@ajaxRequest')
.its('response.body')
.should('contain', 'mailAlertSearchTerm=Handwerk & Produktion')
// or, more specifically using the JSON properties
cy.get('@ajaxRequest')
.its('response.body.results.mailAlertSearchTerm')
.should('contains', 'Handwerk & Produktion');
})
如果您只是截獲并記錄整個事情,您就可以看到這一點。
cy.wait('@ajaxRequest')
.get('@ajaxRequest')
.then((data) => cy.log(data))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/483397.html
標籤:阿贾克斯 柏 qnetwork请求
