【问题标题】:Can't set cookie in the request无法在请求中设置 cookie
【发布时间】:2015-10-02 18:31:02
【问题描述】:

我正在使用可靠库进行 API 测试,似乎无法设置新的 cookie。但是,我可以修改服务器设置的 cookie。

given()
  .cookie("cookie1", "true")
  .get(url)
  .then()
  .assertThat().cookie("cookie1", "true");
// Fails with "Cookie "cookie1" was not
// defined in the response. Cookies are: cookie2=true, cookie3=true


given()
  .cookie("cookie2", "false")
  .get(url)
  .then()
  .assertThat().cookie("cookie2", "false");
// PASS

【问题讨论】:

    标签: java testing junit rest-assured


    【解决方案1】:

    根据REST-assured Documentation,需要调用when()body()方法:

    given()
    .cookie("cookie1", "true")
    .when() // <----
    .get(url)
    .then()
    .assertThat()
    .body(equalTo("true")) // <----
    

    请注意,我从未使用过此 API,我只是根据提供的规范进行推测。

    【讨论】:

    • 感谢您的调查,但这不是问题。 when() 只是语法糖,body 用于断言响应体。响应 cookie 在我的原始帖子中被断言,请参阅code.google.com/p/rest-assured/wiki/…
    【解决方案2】:

    你应该试试这样的

    given().
                    proxy(host("http.proxy.someDomain.com").withScheme("http").withPort(xxxx)).
    

    【讨论】:

    • 你能否给出一些理由以及投票否决?
    猜你喜欢
    • 2013-06-13
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 2017-12-09
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多