以下代码返回的内容取决于如何获取响应并解析它
如何验证响应中的状态代码,内容,网址,类型等
new RestAssured()
.Given()
.Header("Content-Type", "application/json")
.Header("Accept-Encoding", "gzip, deflate")
.Host("http://qa.services.theknot.com")
.Uri("/local-partners/marketplace/v1/storefronts")
.Query("apikey", "ca7f6e91ee8134de9717707d86b29100")
.Body("{ 'Id': [323920, '3a6b4e0b-8e5c-df11-849b-0014c258f21e'] }")
.When()
.Post()
.Then()
.Debug();
答案 0 :(得分:0)
使用.TestBody("string", Func<dynamic, bool>)
或TestStatus("string", Func<int, bool>)
或参阅documentation。
答案 1 :(得分:0)
new RestAssured()
.Given()
.Header("Content-Type", "application/json")
.Header("Accept-Encoding", "gzip, deflate")
.Host("http://qa.services.theknot.com")
.Uri("/local-partners/marketplace/v1/storefronts")
.Query("apikey", "ca7f6e91ee8134de9717707d86b29100")
.Body("{ 'Id': [323920, '3a6b4e0b-8e5c-df11-849b-0014c258f21e'] }")
.When()
.Post()
.Then()
//Here you make your tests on body, status.
// Utilize method AssertAll() to verify all tests performed
//Where "y.result.msg" is extract from json, use http://jsonpath.com to do.
.Debug()
.TestStatus("codResponse", x => x == 200)
.TestBody("msg", y => y.result.msg == "Your response message")
.AssertAll();