在 跑一个cypress 进行ui 操作的用例时, 也可以观察到整个过程触发的API ,但是如果不加验证点的话,如果API 报错了,case还是会当成pass的,所以在进行ui测试的时候
,同时也可以做API测试。cypress也提供了cy. intercept 供使用。https://docs.cypress.io/api/commands/intercept#Syntax
// spying, dynamic stubbing, request modification, etc.
cy.intercept('/users*', { hostname: 'localhost' }, (req) => {
/* do something with request and/or response */
}).as('exampleApi')
// once a request to api responds, this 'cy.wait' will resolve
cy.wait(@exampleApi).then((interception) => {
let newfundsValue = interception.response.body.newfunds;
var rescode = interception.response.statusCode