Ron*_* Li 2 javascript cypress
我正在尝试使用 cypress 测试广告网络调用,如何过滤网络调用并获取响应。

专门用于查询字符串参数
例如这样:
it('Some test', () => {
cy.intercept('/').as('myRequest');
cy.visit('www.example.com');
cy.wait('@myRequest').then((interception) => {
cy.log(interception.response.body);
});
});
Run Code Online (Sandbox Code Playgroud)
要仅侦听广告请求,请使用cy.intercept('/ads'). 记得在打开页面之前设置拦截。
参考: https: //docs.cypress.io/api/commands/intercept