How to ensure that a cookie is NOT present

自作多情 提交于 2021-02-08 04:36:16

问题


What would be a good way in REST Assured to ensure that a cookie is absent? I checked that there are many .cookie and .cookies methods, but none support checking the absence of a cookie.


回答1:


I'm not finding anything OOTB, but this works:

assertThat(response.getCookie("foo"), is(nullValue()));



回答2:


Would fetching all cookies, iterating over it and asserting over that the expected cookie is not present solve your problem? Am i missing something here?




回答3:


You need to extract the response to access the cookies directly. Here's a (hopefully) real world example:

  @Test
  public void traceNotSupported() {
    ExtractableResponse<Response> response =
        given()
            .cookie(SOME_COOKIE)
            .header(SOME_HEADER, "some-value")
        .when()
          .request(Method.TRACE)
        .then()
          .contentType(not(equalTo("message/http")))
          .statusCode(HttpStatus.METHOD_NOT_ALLOWED_405)
          .extract();

    assertFalse(response.headers().hasHeaderWithName(SOME_HEADER));
    assertFalse(response.cookies().containsKey(SOME_COOKIE));
  }


来源:https://stackoverflow.com/questions/43082765/how-to-ensure-that-a-cookie-is-not-present

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!