2015-10-02 100 views
2

我正在使用API​​测试的放心库,它似乎无法设置新的cookie。但我可以修改服务器设置的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 

回答

1

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

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

请注意,我从来没有使用这个API,我只是猜测基础上所提供的规范。

+0

感谢您寻找到它,但是这不是一个问题。 'when()'只是语法糖,'body'是断言响应体。回复cookie与我原来的帖子一致,请参阅https://code.google.com/p/rest-assured/wiki/Usage#Verifying_Response_Data – finspin

-1

你应该尝试这样的事情

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

您可以给出一些推理和投票吗? – san1deep2set3hi