作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法“捕获”与 Cypress 合作的请求。更重要的是,我看不到一些 XHR 请求,但它们在 DevTools 中。我添加了带有箭头的屏幕截图以更好地描述问题。
我无法将我的项目上传到公共(public)存储库,但也许您可以根据测试本身获得一些想法。我没有任何 beforeEach 等。
it('should generate the right request for password change', () => {
cy.visit(`/courses/reset-password?token=${token}&userId=${userId}`);
cy.server();
cy.route('POST', '/auth/local/reset-password').as('resetRequest');
cy.get('#password').type(password);
cy.get('#confirmPassword').type(password);
cy.get('button[type="submit"]').click();
console.log('at the end');
cy.wait('@resetRequest').then((request) => {
// never get here
console.log('fff', request);
console.log('requestBody', request.requestBody);
expect(request.body.newPassword).to.eq(password);
expect(request.body.token).to.eq(token);
expect(request.body.userId).to.eq(userId);
});
});
如果有人有任何想法 - 请与我分享:)
最佳答案
为了能够将 cy.server() 和 cy.route() 与获取请求一起使用,您需要按照此处所述进行操作: https://stackoverflow.com/a/49088084/9947826
关于javascript - Cypress 在命令日志中看不到请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61235428/
我是一名优秀的程序员,十分优秀!