我正在尝试在请求的正文中发布一个json。在此之前,我正在阅读它,然后在空手道框架中使用set方法更新了几个键。但是测试通过了,但在控制台中我看到它显示了400个错误请求错误
与Postman相比,我验证了所有必需的参数。邮递员中设置的相同“邮寄”请求可以正常工作。
Background:
* json foojson = read ('foo.json')
* set foojson.foo = 'foo1'
* set foojson.foo4[0].foo7 = 'fooo8'
Scenario:
Given url
And headers
And json foo1json = foojson
And request foo1json
And print request
When method post
Then status 200
请在下面找到Json示例
{
"foo": "",
"fooA": "",
"fooB": "",
"fooFoo": [
{
"foo1": "foo A",
"foo2": "foo AA",
"foo3": "foo AAAA",
"foo4": {
"foo5": " ",
"foo6": "foo AAAA",
"foo7": "foo AAAA"
},
"foo8": "foo AAAA",
"foo9": 0,
"foo10": 0,
"foo11": [
]
}
],
"fooC": "foo AAAA",
"fooD": [
],
"fooE": ""
}
实际:
场景在这里失败
scenarios: 1 | passed: 0 | failed: 1 | time: 2.2143
但是跟踪显示以下内容:
DEBUG com.intuit.karate - response time in milliseconds: 2156.14
1 < 400
1 < Access-Control-Allow-Credentials: true
1 < Access-Control-Allow-Headers: Origin,Accept,X-Requested-With,Content-Type,Content-Disposition,Access-Control-Request-Method,Access-Control-Request-Headers,X-HTTP-Method-Override,
1 < Access-Control-Allow-Methods: POST, GET, HEAD, OPTIONS, PUT, PATCH, DELETE
1 < Access-Control-Max-Age: 3600
1 < Cache-Control: no-cache
1 < Connection: keep-alive
1 < Content-Security-Policy: child-src 'self'
1 < Content-Type: application/json;charset=UTF-8
具体错误如下:
{“ timestamp”:1557310988561,“ traceId”:“”,“ path”:“ [POST]”“, “错误”:[{“ httpStatusCode”:“ BAD_REQUEST”,“代码”:“ BAD_REQUEST”, “ message”:“ JSON解析错误:无法从START_OBJECT令牌中反序列化
foo
的实例;嵌套的异常是com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从START_OBJECT中反序列化foo
的实例\ n位于[来源:(PushbackInputStream);行:1,列:1]“}]}
请让我知道是否有人可以帮助我
答案 0 :(得分:0)
与Postman相比,我验证了所有必需的参数
这是非常无用的陈述。现在,针对此错误:
无法从START_OBJECT令牌中反序列化foo实例;嵌套的异常是com.fasterxml.jackson.databind.exc.MismatchedInputException
很明显,服务器抛出了此错误,并且看起来空手道已正确发送了JSON,但是您没有提供请求,因此没人能告诉您缺少的信息。
看起来空手道确实在您的服务器中发现了一个错误-这是API测试的整个问题:)因此,请再次检查。
如果您仍然认为空手道存在问题,请执行以下过程:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue