首页 > 解决方案 > 在空手道中调用其他功能文件时如何在读取中传递变量?

问题描述

我有这样的要求-

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

我有这样的脚本。

特征库 -

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

特点1 -

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

此代码不起作用,并给我文件未找到错误。

标签: karate

解决方案


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

请将您的代码更改为:

* def requestBody = read(file)

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


推荐阅读