[英]how can I verify response against a predefined json schema in karate?
Currently for checking answer response IO use below method: 当前用于检查答案响应IO的方法如下:
And match response ==
"""
{
"status":#number,
"message":#string
}
"""
Is there any way to do like below? 有什么办法可以像下面这样吗?
And match response == someJsonSchemaDefinedInKarateConfigFile
Yes, refer to the documentation on reading files . 是的,请参阅有关读取文件的文档。
And match response == read('my-schema.json')
(edit): There was a comment requesting how to initialize these in karate-config.js
(编辑):有一条评论要求如何在
karate-config.js
初始化它们
karate-config.js
is intended for 'global' config, I really don't recommend dumping schemas here unless you are sure it will be used by almost all of your tests. karate-config.js
用于“全局”配置,我真的不建议在这里转储模式,除非您确定几乎所有测试都将使用它。 But if you are reading from a file, it might be ok as it won't be a time consuming operation, remember karate-config.js
is re-loaded for every Scenario
. 但是,如果您正在从文件中读取文件,那可能没问题,因为它不会花费很多时间,请记住,对于每个
Scenario
, 都会重新加载karate-config.js
。
Within karate-config.js
you can easily load a JSON or JS file by using karate.read()
. 在
karate.read()
karate-config.js
您可以使用karate.read()
轻松加载JSON或JS文件。 This should answer your question: 这应该可以回答您的问题:
function() {
var config = {
};
config.mySchema = karate.read('classpath:my-schema.json');
return config;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.