【发布时间】:2017-10-16 20:57:01
【问题描述】:
这是响应(有点)
{
"Cats": [
{
"Code": "XXXX",
"Ven": {
"Description": "Any"
},
},
"Rate": {
"Actual": {
"Amount": "XXX",
"Currency": "USD"
},
"Token": "Cg..........................................",
{
"Code2": "2XXXX",
"Vend": {
"Code": "2X",
"Description": "aNY2"
},
"Token": "Cg...................................",
}
我需要验证响应是否包含 Token 值,如果这个 token 值包含某个字符串,这就是代码
Response responseshop = given().header("Authorization", "Basic
XXXXXXXXXXX=").header("accept-version","2.0.0").header("Accept",
"application/xml").
param("Location", "Geocode,XX.XXXXXX,-XX.XXXXXX").
param("Pick", "2017-12-12").
param("Drop", "2017-12-15").
get("/cats/shop?AppKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
responseshop.then().log().all().
statusCode(200).
body("root.Cats.Rate.Token", containsString("Cg"));
System.out.println("This is the Response");
System.out.println(responseshop);
String Token =responseshop.path("root.Cats.Rate.Token");
System.out.println("This is the Token");
System.out.println(Token);
顺便说一句,响应被打印出来,它也通过了 200 状态验证, 但是我一遍又一遍地得到这个断言错误:
java.lang.AssertionError: 1 expectation failed.
XML path root.Cats.Rate.Token doesn't match.
Expected: a string containing "Cg"
Actual:
Cg........................
我很放心,我是不是错过了什么。 谢谢!
【问题讨论】:
标签: automation rest-assured web-api-testing