一、对XHR api请求加header
cy.server({
onAnyRequest: (route, proxy) => {
proxy.xhr.setRequestHeader('myHeaderKey', 'bestfei')
}
})
二、对页面请求加header
在visit方法加入headers参数,例如:
cy.visit(`${this.route.targetUrl}`,{headers:{'myHeaderKey':'myHeaderValue'}})
三、完整请求
switchToTargetPageWithHeaders() {
cy.server({
onAnyRequest: (route, proxy) => {
proxy.xhr.setRequestHeader('myHeaderKey', 'bestfei')
}
})
cy.visit(`${this.route.targetUrl}`,{headers:{'myHeaderKey':'bestfei'}})
this.spinLoading.should('not.exist')
return this
}
网友评论