在返回存根数据之前,您可以在cy.route方法中访问req对象吗?

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

我希望在柏树路线方法中获取req对象。通过这样做,我可以决定用户在使用具有动态响应的graphql路由时返回的内容。有没有人能够完成这个?

我认为有权访问这将是非常有用的。

cypress
1个回答
0
投票

我希望这有帮助,xhr.requestBody帮助访问请求正文,

cy.route("GET", "/login").as("getLogin");
cy.get("#contactID").type("[email protected]");
cy.contains("Login").click();
cy.wait("@getLogin").then(function(xhr) {
  // we can now access the low level xhr
  // that contains the request body,
  // response body, status, etc
  const request = xhr.requestBody;
  expect(response[0]).to.have.property("SomeKey", "Data");
  const response = xhr.responseBody;
  expect(response[0]).to.have.property("LineName", "Line A");
});
© www.soinside.com 2019 - 2024. All rights reserved.