javascript - 赛普拉斯拦截与 url 不匹配
问题描述
我正在通过网络调用获取数据:
https://mydomain.xxx/third-party-service/pragma?perPage=15&page=1
Request Method: GET
试图用代码拦截它:
// Overriden not to clear localStorage authentication tokens
const clear = Cypress.LocalStorage.clear;
Cypress.LocalStorage.clear = function(keys) {
if (keys) {
return;
}
};
context('Navigation', () => {
before(() => {
cy.login();
cy.visit('/');
});
beforeEach(() => {
cy.get('[data-test=test-burger]').click();
});
it('Tests table', () => {
cy.get('[data-test=invoices]').click();
cy.intercept('**/pragma**').as('getPragmaDocuments');
cy.wait('@getPragmaDocuments');
//....assertions here after API call is waited
});
});
但是,它不会拦截网络请求。
我得到的错误:
5000 毫秒后重试超时:cy.wait() 超时等待 5000 毫秒以等待对路由的第一个请求:getPragmaDocuments。从未发生过请求。了解更多
解决方案
我看到了你的问题,但我不确定你的“修复”为什么有效,哈哈。
您需要在单击cy.intercept()
之前开始,如下所示:
cy.intercept('**/pragma**').as('getPragmaDocuments');
cy.get('[data-test=invoices]').click();
cy.wait('@getPragmaDocuments');
推荐阅读
- javascript - Chrome 扩展程序显示启用/禁用扩展程序的切换
- ansible - 访问角色的默认变量
- python - 在 Python 字典中的字符串中添加重复出现的字母的字符索引
- binary - 补码数的最高位是否指示其符号?
- python - 每次迭代中 i=srqt(i) 时的运行时间/时间复杂度
- http - 在浏览器中,为什么即使在删除缓存/历史记录后 facebook.com 也会自动调用 https://www.facebook.com
- python-3.x - 监视文件目录更改多行返回
- android - 如何等待 TwitterKit Android SDK 的 BroadcastReceiver 中的响应?
- algorithm - 多维背包的蛮力算法
- google-app-engine - Google appengine memcache 在 GWT RPC 调用中抛出 get 调用