We use karate 0.9.5. We would like to make a dynamic Scenario Outline using conditional logic. We would like to retrieve towns for a list of regions, and this for a list of countries. Conditional logic is used only in towns retrieving. What we've done:
Main.feature:
Scenario Outline:
* def countries = call read('GetRegionsWithTowns.feature') { countryId: '#(<id>)' }
Examples:
|countriesList|
GetRegionsWithTowns.feature:
Scenario:
* def fun =
"""
function(regions) {
for (i = 0; i < regions.length; i++) {
var region = regions[i];
if(region['name'] && region['name'].contains('alabama')){
karate.log('***smth');
}
else{
var regionId = region['region_id'];
karate.call('GetTowns.feature', [regionId]);
}
}
}
"""
* def regions = call read('GetRegions.feature') { countryId: '#(countryId)' }
* def result = call fun(regions)
GetRegions.feature
Scenario:
Given url 'someurl'
And path countryId, 'regions'
When method get
Then status 200
GetTowns.feature
Scenario:
Given url 'someurl'
And path regionId, 'towns'
When method get
Then status 200
Error is
GetTowns.feature:16 (the line with "And path regionId, 'towns'") - javascript evaluation failed: regionId, ReferenceError: "regionId" is not defined in <eval> at line number 1
We can't figure out what we are doing wrong? Any help is welcome, thanks