赛普拉斯cy.route2没有捕获请求

时间:2020-10-29 09:53:56

标签: javascript xmlhttprequest 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()终止请求:

enter image description here

0 个答案:

没有答案