finspin
finspin

Reputation: 4061

Can't set cookie in the request

I'm using rest-assured library for the API tests and it seems like a new cookie can't be set. I can however modify the cookie which is set by the server.

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

Upvotes: 2

Views: 1915

Answers (2)

san1deep2set3hi
san1deep2set3hi

Reputation: 5134

You should try something like this

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

Upvotes: 0

Matias Cicero
Matias Cicero

Reputation: 26281

According to REST-assured Documentation, you need to call the when() and body() methods:

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

Please note that I have never used this API and I'm just speculating based on the provided specification.

Upvotes: 1

Related Questions