javascript - Failing wait for request in Cypress - Stack Overflow

I'm wrote wait on 3 different requests on my automated test, but each time I run the test, the wai

I'm wrote wait on 3 different requests on my automated test, but each time I run the test, the wait functions on one of the requests.

 cy
        .intercept('POST', '**/api/Availability')
        .as('availabilecheck');
    cy
        .wait('@availabilecheck')
        .its('response.statusCode')
        .should('eq', 200)

////////////////////////////////////////

        cy
    .intercept('POST','**/api/Availability/GetPrice')
    .as('getpricecheck');
cy
    .wait('@getpricecheck')
    .its('response.statusCode')
    .should('eq', 200);

////////////////////////////

 cy.intercept('POST','**/api/Member/Find')
        .as('memberresponse')
    cy.wait('@memberresponse')

I wrote the above code for 3 different requests but each time I run the test, one of the requests actually waits and the other 2 fails.

What should I do?

I'm wrote wait on 3 different requests on my automated test, but each time I run the test, the wait functions on one of the requests.

 cy
        .intercept('POST', '**/api/Availability')
        .as('availabilecheck');
    cy
        .wait('@availabilecheck')
        .its('response.statusCode')
        .should('eq', 200)

////////////////////////////////////////

        cy
    .intercept('POST','**/api/Availability/GetPrice')
    .as('getpricecheck');
cy
    .wait('@getpricecheck')
    .its('response.statusCode')
    .should('eq', 200);

////////////////////////////

 cy.intercept('POST','**/api/Member/Find')
        .as('memberresponse')
    cy.wait('@memberresponse')

I wrote the above code for 3 different requests but each time I run the test, one of the requests actually waits and the other 2 fails.

What should I do?

Share edited Apr 5, 2021 at 3:43 Tester Unknown asked Apr 3, 2021 at 10:38 Tester UnknownTester Unknown 631 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

The order of mands matters. In my case I had to move the cy.intercept() mand before the action that performed the request

//the intercept es first
cy.intercept("POST", "**/api/user/login").as("loginResponse");

//this performs POST request in my case, es second
cy.get('button[type="submit"]').should("not.be.disabled").click();

//thirdly es the wait
cy.wait("@loginResponse").its("response.statusCode").should("eq", 200);

If the endpoints you are intercepting are not different, then Cypress will only take the first one and discard any subsequent ones. Make sure that the text that you are matching the url against is different for each request.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745045329a4608062.html

相关推荐

  • javascript - Failing wait for request in Cypress - Stack Overflow

    I'm wrote wait on 3 different requests on my automated test, but each time I run the test, the wai

    22小时前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信