How can I pass a variable from one feature file to

2019-08-05 20:04发布

问题:

I have a variable in one of the scenario of a feature file which I need to use in the request body of second feature file.

For Example:

A.feature

Scenario: Test
Given url 'abc'
* def number = 12345
And request {tyu:'#(number)',dhd:'lkj'}
When method put
Then status 200

B.feature

Scenario: Test2
Given url 'pqr'
And request {tyu:'#(number)'}
When method put
Then status 200

Note: Number variable in A.feature is a 6 digit number which is randomly generated everytime and the same should be passed in B.feature file.

回答1:

Normally if you have two Scenario-s that depend on one another you have to combine them into one. Refer the docs here: https://github.com/intuit/karate#script-structure

But if you are really looking for how to initialize something and re-use it across all feature files, maybe you are looking for karate.callSingle(): https://github.com/intuit/karate#hooks

var result = karate.callSingle('get-token.feature');


标签: rest karate