在大纲场景的情况下检索变量

  • 本文关键字:情况下 检索 变量 karate
  • 更新时间 :
  • 英文 :


我想恢复一个对象id(processId(,我在功能中的简单Post请求中传递该id

Given url <url>
And path 'processes'
And header Authorization = 'Bearer ' + <token>
And request process
When method post
Then status 201
* def processId = response.id

我在Scenario大纲(可变<url>(中用3个不同的环境测试这个请求。所以我必须恢复3 id在功能B 中使用它们

我的问题是:如何检索这些ID以用于功能B

感谢

您不可能在另一个Scenario中重用数据,而Feature当然是不可能的。请花点时间阅读以下内容:https://stackoverflow.com/a/46080568/143475

也就是说,如果你只需要在循环中调用一个Scenario,那么就这样做吧。这里有一个简单的例子,你可以试试:

Feature:
Scenario:
* table data
| value |
| 'one' |
| 'two' |
* def result = call read('called.feature') data
* def traceIds = $result[*].traceId
* print traceIds

called.feature简单地说就是:

@ignore
Feature:
Scenario:
* url 'https://httpbin.org/post'
* request { key: '#(value)' }
* method post
* def traceId = response.headers['X-Amzn-Trace-Id']

请阅读文档,了解如何";收集";来自";称为";特征,在这种情况下为traceId:https://github.com/karatelabs/karate#data-驱动特征