如何使用Karate API Testing从一个功能文件到另一个功能文件调用变量 [英] How can I call a variable from one feature file to another feature file using Karate API Testing
本文介绍了如何使用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
一旦调用上述api,就会生成一个ID.我想使用另一个文件中生成的ID来更新数据.我已将ID存储在"newId"变量中.如何在另一个功能文件中使用此变量及其值?
One id will be generated as soon as above api is called. I want to use the id generated in another file to update the data. I have stored the id in 'newId' variable. 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 :)
因此,如果您具有以下功能called.feature
:
So if you have a feature called.feature
as follows:
Feature:
Scenario:
* print newId
您可以将其添加为发布代码的最后一行:
You can add this as the last line of the code you posted:
* call read('called.feature') { newId: '#(newId)' }
这篇关于如何使用Karate API Testing从一个功能文件到另一个功能文件调用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文