How to Use Variable in Feature File

How to use variable in feature file

The easiest way is to write a step specific for returning lines items for "right now":

Given the API returns items for right now

You can call the other version of the step from the new version:

[Given(@"the API returns items for right now")]
public void GivenTheAPIReturnsItemsForRightNow()

This avoids code duplication between steps.

How can I pass a variable from one feature file to other

Normally if you have two Scenario-s that depend on one another you have to combine them into one. Refer the docs here:

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():

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

Passing a variable from one feature file into another as a part of request URL(not query parameter) in Karate

Can you simplify your example ? The only thing I can make out is you need a space after the call feature and before the call argument:

* call read('deleteVehicle.feature') { vehcileId: '#(vehicleId)' }

The pattern we generally recommend is to setUp not tearDown as tearDown has a risk of not executing if you had an error. That said, please see hooks:

Sometimes you should just keep it simple and call a feature (with args) only where you need it.

Returning Variable from Feature File With Multiple Scenarios - Karate

Can't say without seeing your code. But you can try using the @parallel=false annotation in the "calling" feature file:

Otherwise this may be a bug in Karate - so please follow this process:

Related Topics

Leave a reply