[英]Cypress intercept - how to chain multiple assertions on a response
我剛開始使用新的攔截方法,有一個基本問題,想知道如何在一個測試中鏈接下面的兩個斷言。
cy.intercept('GET', '/states').as('states');
cy.reload(true);
// cy.wait('@states').its('response.statusCode').should('eq',200)
cy.wait('@states').its('response.body').should('have.length', 50)
兩個斷言單獨工作。
從.its('response.statusCode')
傳下來的主題是statusCode
屬性的值,所以你需要再次訪問response
來測試這兩個條件
使用閉包為兩個斷言提供response
cy.wait('@states')
.its('response')
.then(response => {
cy.wrap(response).its('statusCode').should('eq', 200)
cy.wrap(response).its('body').should('have.length', 50)
})
使用回調模式
cy.wait('@states')
.its('response')
.should(response => expect(response.statusCode).to.eq(200))
.should(response => expect(response.body.length).to.eq(50))
重讀別名
cy.wait('@states') // wait for the alias
.its('response.statusCode').should('eq', 200)
cy.get('@states') // 2nd time use get()
.its('response.body').should('have.length', 50)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.