我需要使用空手道匹配api的GET响应 . 虽然我能够使用单独匹配来完成它,但它正在成为一堆非常庞大的代码 . 我希望减少代码行 . PFB响应匹配的工作方式 .
GET API RESPONSE是
{
"address": {
"city": "Warsaw",
"street": "1212 Main St",
"postalCode": "22-333"
},
"dateOfBirth": "1996-09-08T00:00:00+0000",
"email": "auth@mail.com",
"id": "123456",
"givenName": "Clap",
"mobilePhone": "23456778787",
"familyName": "Customer"
}
我可以使用下面的方法管理验证
And match header vary == 'origin'
And match header Content-Type == 'application/json; charset=utf-8'
And match header access-control-expose-headers == 'WWW-Authenticate,Server-Authorization'
And match header cache-control == 'no-cache'
And match header accept-ranges == 'bytes'
And match header Content-Length == '225'
And match $.dateOfBirth == '1996-09-08T00:00:00+0000'
And match $.email == 'auth@mail.com'
And match $.id == '123456'
And match $.givenName == 'Clap'
And match $.mobilePhone == '23456778787'
And match $.familyName == 'Customer'
And match response.address.city contains 'Warsaw'
And match response.address.street contains '1212 Main St'
And match response.address.postalCode contains '22-333'
我已经尝试了一些给出的方法,但它对验证没有帮助 .
1 回答
阅读文档 . 您可以在一行中匹配响应JSON:
通常你不需要专注于 Headers ,因为它们往往会根据服务器,操作系统等的类型而改变 . 也许某些测试可以做你正在做的但不是全部 .