英文:
Validate response is empty
问题
We have a 404 response that returns an empty response, but when trying to validate that, we get the following error. Is there a suggested way to evaluate a truly empty response?
我们有一个返回空响应的404响应,但是在尝试验证时,我们遇到了以下错误。是否有建议的方法来评估真正的空响应?
Here is our response, which you can see is empty:
这是我们的响应,您可以看到它是空的:
We have tried the following match test, with no luck.
我们尝试了以下匹配测试,但没有成功。
Reviewed the following github posts, with no luck:
查看了以下GitHub帖子,但没有成功:
Also tried a simple match, versus a karate match with the above evaluations, but those fail as well.
还尝试了简单的匹配,与上面的评估一起使用karate匹配,但那些也失败了。
英文:
We have a 404 response that returns an empty response, but when trying to validate that, we get the following error. Is there a suggested way to evaluate a truly empty response?
* if (responseStatus == 404 ) matchResult = karate.match("$ == ''")
js failed:
>>>>
01: if (responseStatus == 404 ) matchResult = karate.match("$ == ''")
<<<<
org.graalvm.polyglot.PolyglotException: json string can not be null or empty
- com.jayway.jsonpath.internal.Utils.notEmpty(Utils.java:401)
- com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:36)
- com.jayway.jsonpath.JsonPath.parse(JsonPath.java:647)
- com.intuit.karate.Json.of(Json.java:63)
- com.intuit.karate.core.ScenarioEngine.evalJsonPath(ScenarioEngine.java:2000)
- com.intuit.karate.core.ScenarioEngine.evalJsonPathOnVariableByName(ScenarioEngine.java:2053)
- com.intuit.karate.core.ScenarioEngine.evalKarateExpression(ScenarioEngine.java:2085)
Here is our response, which you can see is empty:
We have tried the following match test, with no luck.
* if (responseStatus == 404 ) matchResult = karate.match("$ == ''")
* if (responseStatus == 404 ) matchResult = karate.match("$ == []")
* if (responseStatus == 404 ) matchResult = karate.match("$ == '#[0]'")
* if (responseStatus == 404 ) matchResult = karate.match("$ == '#notpresent'")
* if (responseStatus == 404 ) matchResult = karate.match("$ == '#null'")
Reviewed the following github posts, with no luck:
https://stackoverflow.com/questions/56784911/karate-framework-notnull-and-present-are-not-working-in-case-response-is-emp
https://stackoverflow.com/questions/54933406/karate-dsl-blank-response-passes-tests
Also tried a simple match, versus a karate match with the above evaluations, but those fail as well.
* match $ == []
json string can not be null or empty
* match $ == {}
json string can not be null or empty
* match $ == '#notpresent'
json string can not be null or empty
答案1
得分: 0
尝试:
- 断言 responseBytes.length == 0
请注意,空响应 不是 JSON,所以 $
不会起作用。尝试:
- 匹配 response == ''
英文:
Try:
* assert responseBytes.length == 0
Note that an empty response is not JSON so $
will not work. Try:
* match response == ''
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论