简体   繁体   English

如何使用空手道 API 测试将变量从一个特征文件调用到另一个特征文件

[英]How can I call a variable from one feature file to another feature file using Karate API Testing

Feature: Add data

Scenario: Add unique data

Given url
And request {name: '#(name)', lastName: '#(lastName)'}
And method POST
Then status 200
And def res = response
And def newId = res.data.id

One id will be generated as soon as above api is called.上面的api一被调用就会生成一个id。 I want to use the id generated in another file to update the data.我想使用另一个文件中生成的 id 来更新数据。 I have stored the id in 'newId' variable.我已将 id 存储在 'newId' 变量中。 How can I use this variable and its value in another feature file?如何在另一个功能文件中使用此变量及其值?

This is explained in detail in the documentation - you should actually read it :)这在文档中有详细解释 - 您应该实际阅读它:)

So if you have a feature called.feature as follows:因此,如果您有一个called.feature的功能,如下所示:

Feature:

Scenario:
    * print newId

You can add this as the last line of the code you posted:您可以将此添加为您发布的代码的最后一行:

* call read('called.feature') { newId: '#(newId)' }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 空手道 API 测试 - 将变量从一个特征文件传递到另一个 - Karate API Testing - Passing variable from one feature file to another 空手道 Api 测试 - 如何将数据从一个特征文件传递到另一个特征文件 - Karate Api Testing - How to pass data from one feature file to another 空手道:将变量从一个特征文件传递到另一个作为查询参数 - Karate : Passing variable from one feature file to another as a query parameter 我们可以使用空手道从另一个功能中调用场景吗? - Can we call a scenario from one feature in another using karate? 我可以使用空手道dsl将值从一个文件夹的一个功能文件传递到/ src / java / test下的另一个文件夹的另一个功能文件 - Can I pass values from one feature file of one folder to another feature file of another folder under /src/java/test using karate dsl 我如何使用 1 个参数在空手道功能文件中调用 js function - How can i call the js function in karate feature file with 1 argument 如何传递 karate.prevRequest 和 response 是 arguments 从一个功能文件到另一个功能文件 - How to pass karate.prevRequest and response are the arguments from one feature file to another feature file 空手道 API 测试 - 如何在同一功能中使用从 API 1 到另一个 API 的变量(响应输出) - Karate API Testing - How to use a variable (output from response) from API 1 to another API in same feature Karate-afterFeature - 主要特征文件不能使用 Karate-afterFeature 调用另一个特征文件 - Karate-afterFeature - main feature file cannot call another feature file using Karate-afterFeature 空手道 api 测试 - 如何从命令行读取标签名称到功能文件 - karate api testing - How to read tag names from command line to feature file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM