Karate 我可以在JSON文件中包含所需的所有JSON路径,并在功能文件中使用它进行匹配或其他操作吗?
例如,我保存path.json并添加以下内容。我知道在我尝试的方式中有一个错误,但却找不到Karate 我可以在JSON文件中包含所需的所有JSON路径,并在功能文件中使用它进行匹配或其他操作吗?,karate,Karate,例如,我保存path.json并添加以下内容。我知道在我尝试的方式中有一个错误,但却找不到 { "name": "JSON Path's", "description": "This mainly store the paths of the JSON elements which are validated in each scenario", "SC_4": { "appHeader": "$.testResponse.applicationHeader", "P
{
"name": "JSON Path's",
"description": "This mainly store the paths of the JSON elements which are validated in each scenario",
"SC_4": {
"appHeader": "$.testResponse.applicationHeader",
"ProductsAction": "$.testResponse.applicationHeader.item.action"
}
}
* def attributes = read('../jsonpaths/paths.json')
Given url endPointURL
And request baseJsonRequest
When method post
Then status 200
* def appHeaderSecondTry = attributes.SC_4.appHeader
* print appHeaderSecondTry
哇,这么快你就要成为空手道的高手了:p 好的,就我个人而言,我不建议像你正在做的那样尝试在空手道上构建一个微型框架,我可以看到你正在尝试做什么——保持所有断言“声明性”,并尝试为实际的HTTP调用重用公共代码等等 我的观点是,您只需保存很少的代码行(因为在空手道中发出HTTP请求是多么容易)。此外,您应该能够通过
call
关键字重新使用功能文件。我敦促你在测试中尽量保持匹配语句“正常”
也就是说,您缺少的是karate.eval()
操作,请在文档中查找它。下面是一个示例(第91行):