karate - 空手道:将 jsonPath 发送到另一个功能时,“设置”功能看不到该 jsonPath
问题描述
我有两个功能:第一个是我有参数的地方,第二个是我想从第一个功能发送参数的地方。
第一个特点:
Feature: test
@dev
Scenario: test
* def arguments = { value: '123.00', jspath: '..transferData.amount',consent_body: 'classpath:consent_domestic.json' }
* def createConsentResult = call read('classpath:reuseable/features/changeConsentBody.feature') arguments
第二个特点:
@ignore
Feature: Change consent body - 1 parameter
Background:
* url ''
* call read('classpath:reuseable/features/commonFunction.feature')
@act
Scenario : Change consent body - 1 parameter
* path 'consents'
* def consentBody = read(consent_body)
* print "jsonPath: "+jspath
* set consentBody jspath= value
When request consentBody
And method post
Then status 201
这里* def consentBody = read(consent_body)
karate 将 'consent_body' 视为一个变量并使用该变量的值。
这里* print "jsonPath: "+jspath
karate 将 'jspath' 视为一个变量,并使用该变量的值并打印:[print] jsonPath: ..transferData.amount
。
但是这里* set consentBody jspath = value
的空手道没有将 'jspath' 视为一个变量,也没有使用这个变量的值。相反,空手道显示错误:
changeConsentBody.feature:17 - unexpected path: jspath
在这种情况下,空手道需要将“jspath”视为变量并使用该变量的值。
解决方案
抱歉,如果您真的希望人们有耐心去解决问题并理解问题,那么您的问题必须简化。以后请参考:https ://stackoverflow.com/help/mcve
也就是说,我在这里看到了两个明显的问题。=
顺便说一句,请在标志的每一侧保留空白:
* set consentBody jspath = value
变量不适用于set
命令。而且你不能使用 JsonPath。如果你有动态路径,你可以这样做,参考:https ://github.com/intuit/karate#eval
* def foo = {}
* def path = 'bar'
* eval foo[path] = 'baz'
* match foo == { bar: 'baz' }
如果您想“批量”更新数组,而不是..transferData.amount
- 请使用以下karate.map()
操作:
* def foo = [{},{}]
* def fun = function(x){ x.transferData = { amount: 100 }; return x }
* def res = karate.map(foo, fun)
* match res == [{ transferData: { amount: 100 } }, { transferData: { amount: 100 } }]
最后我敦促你仔细阅读这篇文章,尽量避免“通用”测试用例和使用call
,它只会使事情不必要地复杂化:https ://stackoverflow.com/a/54126724/143475
推荐阅读
- hiqpdf - HiQPdf 问题 获取问题
- linux - 具有参数值和可选标志的 Bash 脚本
- android - 在firebase中发送带有推送通知的可重定向链接 - RN
- swiftui - 按钮单击转到swiftui中的另一个页面
- algorithm - 关于 Substrate Framework 上的 HotStuff 共识实现
- r - 有没有办法对R中的功能数据进行傅里叶基础平滑
- github - 如何为 GitHub 上的源代码 (.zip) 下载添加文件
- flutter - 如何在 workmanager 插件的任务中调用 setState()
- r - 清理 R data.table 中的字符串和数字列
- c# - 使用异步回调了解 Dispatcher.RunAsync 并等待 UI 相关任务