支持从方案大纲传递到JSON文件 [英] Support passing from Scenario Outline to JSON file

查看:30
本文介绍了支持从方案大纲传递到JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am going to reuse some features and calling multiple features in a Scenario Outline. Since the features being called are common, we would like to define its parameters in its own parameter file, while the parameter values are defined in placeholder.

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

We hope the placeholder can get the value from the Outline Examples.

如何制作?

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

feature_1.json

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

feature_2.json

feature_2.json

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

推荐答案

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

I think the version currently in development will make this possible. Can you take a look at this GitHub issue and see if this addresses your question: https://github.com/intuit/karate/issues/717

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

It will also be great if you can build from source and try this new capability.

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   |

这篇关于支持从方案大纲传递到JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆