简体   繁体   English

如何为 ArrayList 或 JsonArray 中的每个元素调用功能文件以生成 Get 请求(由 Java function 创建)

[英]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:背景:

  • def ss = 'https:testingurl/'+ < spaceCode > + 'trailPath'; def ss = 'https:testingurl/'+ <spaceCode> + 'trailPath';

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问题

  1. how to run above file for each element of the "spaceList" which is an Java ArrayList, i am creating this ArrayList by calling method getSpaceList()如何为“spaceList”的每个元素运行上面的文件,这是一个 Java ArrayList,我正在通过调用方法 getSpaceList() 创建这个 ArrayList

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.

相关问题 空手道 - 如何生成一份 cucumber 报告,而不是为每个特征文件生成一份报告 - Karate - How to get one cucumber report generated instead of one for each feature file 如何在另一个功能文件的 javascript Function 中调用我的功能文件 function? - How can I call my feature file function in javascript Function of another feature file? 我如何使用 1 个参数在空手道功能文件中调用 js function - How can i call the js function in karate feature file with 1 argument 空手道 - 如何通过 java 获取功能文件名 - Karate - How to get feature file name through java 如何在空手道功能文件中调用特定的 javascript function from.js 文件 - How to call a particular javascript function from .js file in karate feature file 如何使用空手道功能文件中的 .js 文件中的参数调用 Javascript 函数 - How to call a Javascript function with arguments from .js file in karate feature file 空手道中如何在for循环中调用功能文件? - How to call a feature file inside a for loop in karate? 如何为每次执行json数组循环调用其他功能 - How to call some other feature for each execution of json array loop 功能文件中存在的 JavaScript 函数内的 API 调用 - API call inside a JavaScript function present in a feature file 如何直接在空手道特征文件中获取Java类的静态变量的值 - How to get value of the static variable of the java class in karate feature file directly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM