I have a feature file that reads a csv file with multiple rows and I need to validate that if two of the columns meet certain conditions, the third column needs to be mandatory. I have tried using a js function however I am unsure as to how I should call this function for the third column. So based on the example below, if the name is Chicken, the unit kg then the cost needs to be mandatory.
#
noinspection CucumberTableInspection
Feature: Serverless
Scenario Outline: Per Row *
def row =
""
" {
name: '<Name>',
unit: '<Unit>',
cost: '<Cost>',
}
@FunctionComparison
""
" *
def name = '<Name>' *
def unit = '<Unit>' *
def cost = '<Cost>' *
def checkMandatory =
""
"
function(arg1, arg2, arg3) {
if (arg1 in ('Chicken')) {
if (arg2 in ('kg')) {
if (arg3.length < 0) {
return false;
}
return true;
}
return true;
}
return true;
}
""
" *
match row ==
""
" {
name: '#ignore',
unit: '#regex ea|kg|ml',
cost: 'checkMandatory(name, unit, cost) == true'
}
""
"
Examples:
|
read('input' + '.csv') |
The input.csv is simply a csv file with the following:
Line,Name,Unit,Cost (Columns)
1,Cheese,ea,34.50 2,Cake,ea,55.54 3,Chicken,kg, 4,Cement,ml,4.32