如何在空手道中调用其他功能文件时在读取中传递变量?

How to pass variables in read while calling other feature files in Karate?

我有这样的需求-

  1. feature1 调用 featurebase 文件。
  2. 在特征库文件中,我正在阅读 json。
  3. 我想配置通过featurefile1读取文件。

我有这样的脚本。

特征库 -

Background:
    * url baseUrl
    * def requestBody = read('#(file)')

功能 1 -

Background:
    * url baseUrl
    * def callFeature = call read('FeatureBase.feature') { file: 'json1.json'}

此代码无效,提示我找不到文件错误。

'#(foo)' 技巧仅适用于 JSON。请阅读:https://github.com/intuit/karate#rules-for-embedded-expressions

请将您的代码更改为:

* def requestBody = read(file)

是的,就是这么简单,就像普通的一样JavaScript。