【问题标题】:Can you access the req object in the cy.route method before returning the stubbed data?在返回存根数据之前,您可以访问 cy.route 方法中的 req 对象吗?
【发布时间】:2019-04-23 15:24:42
【问题描述】:

我希望在 cypress 路由方法中获取 req 对象。通过这样做,我可以决定用户在点击具有动态响应的 graphql 路由时会返回什么。有没有人能够做到这一点?

我认为访问它会非常有用。

【问题讨论】:

    标签: cypress


    【解决方案1】:

    我希望这会有所帮助,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");
    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      相关资源
      最近更新 更多