[英]how to call a feature file to generated a Get request , for each element in an ArrayList or JsonArray ( Created by Java function )
basically I want to achieve below result, where the list used in Examples: is dynamic基本上我想实现以下结果,其中 Examples: 中使用的列表是动态的
Scenario Outline:情景大纲:
def ss = 'https:testingurl/'+ < spaceCode > + 'trailPath'; def ss = 'https:testingurl/'+ <spaceCode> + 'trailPath';
Given url ss给出 url SS
And header Authorization = autGetToken()和 header 授权 = autGetToken()
When method get当方法得到
Then status 200然后状态200
Examples:例子:
| spaceCode | | space1| | spac2| | spaceAbc05| | space.o2| | spacesacc| | spacere |
So I created one.feture and tried to call it from other feature file所以我创建了 one.feture 并尝试从其他功能文件中调用它
one.feature one.feature
Background:背景:
Scenario: need to run this scenario for each member of the spaceList ArrayList / JsonArray场景:需要为spaceList ArrayList / JsonArray的每个成员运行这个场景
Given url ss
And header Authorization = autGetToken()
When method get
Then status 200
* print response
* def count = response.value.length
* print count
* karate.set('total', karate.get('total') + karate.get('count') )
* print total
question问题
i have tried to call it from other feature file like below我试过从其他功能文件中调用它,如下所示
Method1方法一
caller.feature caller.feature
Background:背景:
* def total = 0
* def helper = Java.type('shared.Helper')
Scenario Outline: calling other feature file for each element of the spaceList Array场景大纲:为 spaceList 数组的每个元素调用其他特征文件
def result = call read('one.feature')
Examples:例子:
| spaceCode |
| helper.getSpaceList() |
Method2 caller.feature方法 2 caller.feature
Background:背景:
* def total = 0
* def helper = Java.type('shared.Helper')
* def spaceList = helper.getSpaceList() // this returns around 20 different elements from a sql
Scenario Outline: calling other feature file for each element of the spaceList Array场景大纲:为 spaceList 数组的每个元素调用其他特征文件
def result = call read('one.feature')
Examples:例子:
| spaceCode |
| spaceList |
i have also tried karate.forEach and karate.setUp我也试过 karate.forEach 和 karate.setUp
Try this example.试试这个例子。 Note how it will make two POST requests.
请注意它将如何发出两个 POST 请求。 Once you understand this, you should be able to do what you want.
一旦你明白了这一点,你应该能够做你想做的事。
Feature:
Scenario Outline:
* url 'https://httpbin.org/anything'
* request __row
* method post
* status 200
Examples:
| [{ a: 1 }, { a: 2 }] |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.