0

金牛座允许我组合这样的场景

scenarios:
  create-bob-account:
    requests:
    - url: http://example.com/account/create
      method: POST
      body:
        account_owner: bob
        account_number: 123
  create-lisa-account:
    requests:
    - url: http://example.com/account/create
      method: POST
      body:
        account_owner: lisa
        account_number: 321
  account-transfer:
    requests:
    - include-scenario: create-bob-account
    - include-scenario: create-bob-account
    - url: http://example.com/transfer
      method: POST
      body:
        account_number_from: 123
        account_number_to: 321
   ...

在这个例子中,我有重复的代码来创建关于 accout bob 和 lisa 的信息。我可以参数化创建帐户方案吗?即创建脚本

scenarios:
  create-account:
    requests:
    - url: http://example.com/account/create
      method: POST
      body:
        account_owner: ${owner}
        account_number: ${number}

并用不同的变量调用它,像这样

scenarios:
  account-transfer:
    requests:
    - include-scenario: 
         arugment: bob, 123
         create-account 
      - include-scenario: 
         arugment: lisa, 321
         create-account 
    - url: http://example.com/transfer

也许有一些方法可以实现这个功能?基本思想是识别独立于特定变量的脚本,并在各种脚本中使用所需的变量重用它们。

谢谢!

4

1 回答 1

1

CSV 数据集配置怎么样?这样,您可以将您的帐户名称和 ID 放入 CSV 文件中,并包含请求块以从 CSV 文件中读取这些名称/ID 组合,相关的 Taurus 指令是data-sourcesinclude-scenarios

示例 YAML 配置:

execution:
  - scenario: account-transfer

scenarios:
  account-create:
    data-sources:
      - details.csv
    requests:
      - url: http://example.com/account/create
        method: POST
        body:
          account_owner: ${account_owner}
          account_number: ${account_number}
  account-transfer:
    requests:
      - include-scenario: account-create
      - include-scenario: account-create
      - url: http://example.com/transfer
        method: POST
        body:
          account_number_from: 123
          account_number_to: 321
于 2020-01-20T14:38:10.520 回答