2

I am running a SQL query and returning objects as array in karate. I know how to read the first record/row returned. I need to know how to create a loop to read all the records, one at a time.

Here's the start where the SQL query is called and I am assigning objects to variables.

Scenario Outline: Premium-IC or IR Invoice Type  
* def op_ic_ir_query = karate.readAsString('classpath:Payments/
CSC_Payments_API/Queries/qry_Get_Overpayment_IC_IR.txt')
* def OP1 = Stardb.readRows(op_ic_ir_query)
* def OP_cpid = OP1[0].CONTRACT_PAYMENT_ID
* def OP_cid = OP1[0].CONTRACT_ID
* def OP_iid = OP1[0].INVOICE_ID
* def OP_Idate = OP1[0].INVOICE_DATE
* def OP_dtp = OP1[0].DATE_TO_PROCESS
* def transactionAmt = OP1[0].TRANSACTION_AMOUNT
* def invoiceAmt = OP1[0].INVOICE_AMOUNT
* def taxAmt = OP1[0].TAX_AMOUNT
* def paidAmt = OP1[0].PAID_AMOUNT

The next step is calculating an overpayment amount.

# Calculate overpayment_amount - need to keep rolling total for 
overpayment amount.
* def overpaymentAmt1 = (transactionAmt - ((invoiceAmt + taxAmt) - 
paidAmt))
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

0

Here are the ways to do loops in Karate:

1) Scenario Outline and Examples

2) Using call and a second feature file

3) Using JS

Depending on what you want to do, maybe you should the loop in Java code itself, if it simplifies things.

My recommendation would be (2) since you have a dynamic array you need to loop over. So if foo is an array of JSON-s:

* def result = call read('second.feature') foo
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248