【发布时间】:2019-07-17 20:47:40
【问题描述】:
我有两种不同的回答:
{
"id": "U204204",
"title": "Safety kit",
"categoryPath": "/equipment/accessories/null",
"keyFeature": false,
"description": "test",
"price": 24.5,
"availability": "optional-extra",
"technologyItems": [],
"bespoke": false
}
或/和
{
"id": "GWW1WW1",
"title": "Winter pack",
"categoryPath": "/comfort & convenience/packs/null",
"keyFeature": false,
"description": "test",
"price": 410,
"availability": "optional-extra",
"technologyItems": [],
"bespoke": false
}
现在我要断言的是,只要上述 2 个响应中的任何一个中的关键 price 具有以“.5”结尾的值,就可以通过它。
我尝试了以下和类似的方法,但没有奏效:
Given path 'endpoint'
And multipart file pdbData = { read: 'json/PostRequest_201_3.json', filename: 'PostRequest_201_3.json', contentType: 'application/json'}
When method post
And status 201
* def NewpdbId = response.id
And path 'endpoint'+NewpdbId+'/V3FOY3DG'
And method GET
And status 200
* string aa = response.options[13].price
* string bb = response.options[16].price
* def expected = aa contains "#redgex .+[.5]+" ? { pass: true }
* def expected = bb contains "#regex .+[.5]+" ? { pass: true }
* string expected = expected
And match expected == { pass: true }
因此,如果键 price 在任何响应中以“.5”结尾,则应该是通过。如果关键 price 是 all 响应中的整数,那么它应该会失败。
有什么想法吗?我尝试了很多不同的方法
【问题讨论】:
标签: karate