支持从方案大纲传递到JSON文件

时间:2019-05-13 14:45:35

标签: karate

我将重用一些功能并在方案大纲中调用多个功能。 由于调用的功能是通用的,因此我们希望在其自己的参数文件中定义其参数,而参数值在占位符中定义。

我们希望占位符可以从大纲示例中获取值。

如何制作?

Feature: verify parameter passing

  Scenario Outline: verify 2 calls
    * def result1 = call read('baseFeature1.feature')

    * def result2 = call read('baseFeature2.feature') result1

    * print result2

    Examples:
      | fooValue |
      | value1 |
      | value2 |
Feature: feature to verify the parameter passing, no input parameter

Scenario: feature 1

  Given def payload = read('classpath:feature_1.json')

  * print 'feature 1' + payload

  Given def result = { "barValue": "barValue"}

Feature: feature to verify the parameter passing, with input parameter from last step

Scenario: feature 2

  Given def payload = read('classpath:feature_2.json')

  * print payload

feature_1.json

{
  "foo": "#(fooValue)"
}

feature_2.json

{
  "foo": "fooValue",
  "bar": "#(result1.barValue)"
}

1 个答案:

答案 0 :(得分:1)

我认为当前正在开发的版本将使这成为可能。您可以看看这个GitHub问题,看看是否能解决您的问题:https://github.com/intuit/karate/issues/717

如果您可以从源代码构建并尝试此新功能,那也将很棒。

Scenario Outline: magic variables with embedded expressions
  * def expected = __num == 0 ? { name: 'Bob', alive: false } : { name: 'Nyan', alive: true }
  * match expected == { name: '#(__row.name)', alive: '#(__row.alive)' }
  * eval karate.set(__row)
  # you can read from a re-usable JSON file instead of the line below
  * match expected == { name: '#(name)', alive: '#(alive)' }

  Examples:
    | name | alive! |
    | Bob  | false  |
    | Nyan | true   |