空手道 - 我可以在场景大纲中发送多个动态数据吗
Karate - Can i send multiple dynamic data in Scenario Outline
下面是代码:
Feature:
Background:
* def Json = Java.type('Json')
* def dq = new Json()
* def result = dq.makeJson()
* def Sku = dq.makeSku()
Scenario Outline: id : <id>
* print '<id>' #From result
* print '<abc>' #From Sku
Examples:
|result|Sku|
以下是我需要的输出。空手道可以吗?
If i have id = {1,2} and abc = {3,4} i want output to be
id = 1 and abc = 3
id = 1 and abc = 4
id = 2 and abc = 3
id = 2 and abc = 4
对于 2 个以上的变量输入也可以这样做吗?
自己编写排列逻辑,用结果构建一个数组。
请注意,您可以使用 karate.forEach()
迭代 JSON 的键值对
然后使用数据驱动的循环调用(第二个特征文件):
# array can be [{ id: 1, abc: 3 }, {id: 1, abc: 4 }] etc
* def result = call read('second.feature') array
或动态场景大纲:
Scenario Outline:
* print 'id = <id> and abc = <abc>'
Examples:
| array |
参考:
https://github.com/intuit/karate#data-driven-features
https://github.com/intuit/karate#dynamic-scenario-outline
下面是代码:
Feature:
Background:
* def Json = Java.type('Json')
* def dq = new Json()
* def result = dq.makeJson()
* def Sku = dq.makeSku()
Scenario Outline: id : <id>
* print '<id>' #From result
* print '<abc>' #From Sku
Examples:
|result|Sku|
以下是我需要的输出。空手道可以吗?
If i have id = {1,2} and abc = {3,4} i want output to be
id = 1 and abc = 3
id = 1 and abc = 4
id = 2 and abc = 3
id = 2 and abc = 4
对于 2 个以上的变量输入也可以这样做吗?
自己编写排列逻辑,用结果构建一个数组。
请注意,您可以使用 karate.forEach()
然后使用数据驱动的循环调用(第二个特征文件):
# array can be [{ id: 1, abc: 3 }, {id: 1, abc: 4 }] etc
* def result = call read('second.feature') array
或动态场景大纲:
Scenario Outline:
* print 'id = <id> and abc = <abc>'
Examples:
| array |
参考: https://github.com/intuit/karate#data-driven-features https://github.com/intuit/karate#dynamic-scenario-outline