【发布时间】:2019-04-23 15:24:42
【问题描述】:
我希望在 cypress 路由方法中获取 req 对象。通过这样做,我可以决定用户在点击具有动态响应的 graphql 路由时会返回什么。有没有人能够做到这一点?
我认为访问它会非常有用。
【问题讨论】:
标签: cypress
我希望在 cypress 路由方法中获取 req 对象。通过这样做,我可以决定用户在点击具有动态响应的 graphql 路由时会返回什么。有没有人能够做到这一点?
我认为访问它会非常有用。
【问题讨论】:
标签: cypress
我希望这会有所帮助,xhr.requestBody 确实有助于访问请求正文,
cy.route("GET", "/login").as("getLogin");
cy.get("#contactID").type("email@gmail.com");
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");
});
【讨论】: