调用带有变量的空手道功能

时间:2018-07-19 20:32:27

标签: cucumber-jvm karate

在空手道中,您可以通过发送json / list和map来调用功能。我尝试过多种方法来发送值并在调用的功能中使用它,但会引发错误

例如:

  

抛出错误:路径:$,实际:”,预期:   '30e093da-c4e3-4ee0-b180-e5d0b4302d9f',原因:不是子字符串

步骤:* call read('Logcheck.feature') {requestId : "#(responseHeaders['request-id'][0])"}

在logCheck功能中,我尝试使用#(requestId)

获取requestId

日志检查功能步骤

* 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')

例如:

  

引发错误:com.intuit.karate.exception.KarateException:   javascript评估失败:utils.getResultFromLog(baseUrl,'#>   (requestId)','service'),null

打印请求输出为

  

[print] {“ requestId”:“ c996f752-c288-40c7-9398-c913254971e6”}

1 个答案:

答案 0 :(得分:0)

您需要清楚使用嵌入式表达式,请再次阅读文档: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