如何让Cypress等待.intercept请求完成?

问题描述 投票:0回答:1

代码:

describe("Cypress", () => {
  it("Example Test", () => {
    cy.intercept("GET", "/api/**").as("getApi");
    cy.visit("/home/");
    cy.wait("@getApi");
    console.log("here");
  });
});

输出:

here
Request Finished: /api/1/
Request Finished: /api/2/

有没有办法让 Cypress 等待它拦截的请求完成后再继续?

所需输出:

Request Finished: /api/1/
Request Finished: /api/2/
here

注意:页面代码

$.get(url).done(function (response) {
  console.log("Request Finished", this.url);
});
async-await cypress
1个回答
0
投票

你想要这样的东西

cy.intercept("GET", "/api/1/*").as("getApi1");
cy.intercept("GET", "/api/2/*").as("getApi2");
cy.visit("/home/");
cy.wait(['@getApi1', '@getApi2']);
© www.soinside.com 2019 - 2024. All rights reserved.