首页 > 解决方案 > 赛普拉斯 cy.route2 没有收到请求

问题描述

我有一个登录页面,我想用 Cypress 进行测试,并且我想利用新功能的动态响应route2功能。我对作品的原始测试cy.route()

 cy.server();
 cy.route({method: 'POST', url: '/api/login', status: 401, response: {
   code: 401,
   message: "Invalid credentials"
 }}).as('login_xhr');

cy.route2()不是:

        cy.route2('/api/login',  {
                statusCode: 401, 
                body: {
                    code: 401,
                    message: "Invalid credentials"
                }
            }).as('login_xhr');

我在这里做错了什么?对于这两种情况,检查的其余部分如下所示:

cy.get('.tab-pane.active input[name="email"]').type('test@exmaple.com');
        cy.get('.tab-pane.active input[name="password"]').type('wrong_pw');
        
        cy.contains('button', 'Login').click();
        cy.wait('@login_xhr');

cy.route2()请求也被中止:

在此处输入图像描述

标签: javascriptxmlhttprequestcypress

解决方案


推荐阅读