我正在为 API 测试使用 rest-assured 库,似乎无法设置新的 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
最佳答案
根据 REST-assured Documentation , 你需要调用 when()
和 body()
方法:
given()
.cookie("cookie1", "true")
.when() // <----
.get(url)
.then()
.assertThat()
.body(equalTo("true")) // <----
请注意,我从未使用过此 API,我只是根据提供的规范进行推测。
关于java - 无法在请求中设置 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32913594/