使用变量调用空手道功能
Calling karate feature with variable
在空手道中,您可以通过发送 json/list 和地图来调用功能。我尝试通过多种方式发送值并在调用的功能中使用它,但它会抛出错误
例如:
Error thrown : path: $, actual: '', expected:
'30e093da-c4e3-4ee0-b180-e5d0b4302d9f', reason: not a sub-string
步骤:* call read('Logcheck.feature') {requestId : "#(responseHeaders['request-id'][0])"}
在 logCheck 功能中,我尝试使用 #(requestId)
获取 requestId
Logcheck 功能步骤
* def resultFromServiceLog = utils.getResultFromLog(baseUrl,'#(requestId)','service')
我尝试了另一种方法,将其分配给
* def x = {requestId : responseHeaders['request-id'][0]}
* call ('logcheck.feature;) x
我将发送 json
的另一种方法
* json req = {requestId : "#(responseHeaders['request-id'][0])"}
* call read('logcheck.feature') req
步骤logcheck.feature
* print req
* def resultFromServiceLog = utils.getResultFromLog(baseUrl,'#(requestId)','service')
例如:
Error thrown : com.intuit.karate.exception.KarateException:
javascript evaluation failed: utils.getResultFromLog(baseUrl,'#>
(requestId)','service'), null
打印请求输出为
[print] {"requestId": "c996f752-c288-40c7-9398-c913254971e6"}
您需要清楚使用嵌入表达式,请再次阅读文档:https://github.com/intuit/karate#rules-for-embedded-expressions
例如这是错误的:
* def resultFromServiceLog = utils.getResultFromLog(baseUrl,'#(requestId)','service')
改为:
* def resultFromServiceLog = utils.getResultFromLog(baseUrl, requestId, 'service')
这是错误的:
* call ('logcheck.feature') x
你的意思可能是:
* call read('logcheck.feature') x
在空手道中,您可以通过发送 json/list 和地图来调用功能。我尝试通过多种方式发送值并在调用的功能中使用它,但它会抛出错误
例如:
Error thrown : path: $, actual: '', expected: '30e093da-c4e3-4ee0-b180-e5d0b4302d9f', reason: not a sub-string
步骤:* call read('Logcheck.feature') {requestId : "#(responseHeaders['request-id'][0])"}
在 logCheck 功能中,我尝试使用 #(requestId)
Logcheck 功能步骤
* def resultFromServiceLog = utils.getResultFromLog(baseUrl,'#(requestId)','service')
我尝试了另一种方法,将其分配给
* def x = {requestId : responseHeaders['request-id'][0]}
* call ('logcheck.feature;) x
我将发送 json
的另一种方法* json req = {requestId : "#(responseHeaders['request-id'][0])"}
* call read('logcheck.feature') req
步骤logcheck.feature
* print req
* def resultFromServiceLog = utils.getResultFromLog(baseUrl,'#(requestId)','service')
例如:
Error thrown : com.intuit.karate.exception.KarateException: javascript evaluation failed: utils.getResultFromLog(baseUrl,'#> (requestId)','service'), null
打印请求输出为
[print] {"requestId": "c996f752-c288-40c7-9398-c913254971e6"}
您需要清楚使用嵌入表达式,请再次阅读文档:https://github.com/intuit/karate#rules-for-embedded-expressions
例如这是错误的:
* def resultFromServiceLog = utils.getResultFromLog(baseUrl,'#(requestId)','service')
改为:
* def resultFromServiceLog = utils.getResultFromLog(baseUrl, requestId, 'service')
这是错误的:
* call ('logcheck.feature') x
你的意思可能是:
* call read('logcheck.feature') x