1

I'm reading an xml file to build it dynamically using a table.

Scenario: Create subscriber base
    * table data
    |PaidMode|BillCycleCredit|BillCycleType|PrimaryOffer|SubscriberNo    |
    |'0'     |'100000'           |'1'          |'500033'    |'#(postPaidSubscriber1)'|
    |'0'     |'100001'           |'1'          |'500035'    |'#(postPaidSubscriber2)'|
    * def Request = read('newSubscriber.xml')
    And request Request
    * print Request

My xml file (exert):

<NewSubscriberRequest>
        <new1:Customer>
            <shar:FirstName>#(FirstName)</shar:FirstName>
            <shar:LastName>#(LastName)</shar:LastName>
            <shar:LangType>#(LangType)</shar:LangType>
        </new1:Customer>
        <new1:Account>
            <shar:PaidMode>#(PaidMode)</shar:PaidMode>
            <shar:BillCycleCredit>#(BillCycleCredit)</shar:BillCycleCredit>
            <shar:CreditCtrlMode>#(CreditCtrlMode)</shar:CreditCtrlMode>
            <new1:BillCycleType>#(BillCycleType)</new1:BillCycleType>
        </new1:Account>

I've had a look at this solution, How to use dynamic values for Karate Features, he seams to want to do the same thing but it doesnt work for me i get the below error.

feature call loop failed at index: 0, match failed: EQUALS
  $ | not equal | match failed for name: 'SubscriberNo' (MAP:MAP)
  {"PaidMode":"0","BillCycleCredit":"100000","BillCycleType":"1","PrimaryOffer":"500033","SubscriberNo":"#(postPaidSubscriber1)"}
  {"PaidMode":"0","BillCycleCredit":"100000","BillCycleType":"1","PrimaryOffer":"500033","SubscriberNo":"#(postPaidSubscriber1)"}

    $.SubscriberNo | not equal (STRING:STRING)
    '#(postPaidSubscriber1)'
    '699111115'

I'm now here https://github.com/karatelabs/karate/blob/v1.2.0/karate-junit4/src/test/java/com/intuit/karate/junit4/xml/xml.feature again trying to figure out how best to do this. This question is similar to my previous question How to set a variable in the xml per scenario just want to read it from a table to create my subscriber base basically for readability and usage reasons. Sorry Peter I see you get alot of these type of questions (second from me alone lol). I just need a little nudge I think

imp
  • 435
  • 6
  • 20

1 Answers1

1

I really think you don't need to do this in a table: '#(postPaidSubscriber1)' - just use the variable name as-is. Refer the docs: https://github.com/karatelabs/karate#table

* table data
    |PaidMode|BillCycleCredit|BillCycleType|PrimaryOffer|SubscriberNo   |
    |0     |100000           |1          |500033    |postPaidSubscriber1|
    |0     |100001           |1          |500035    |postPaidSubscriber2|
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Excuse the late reply, work work... I didnt realise I could do this :( thanks. I've tried this so far, I'm still missing something and I assume its because i havent written js function to write 'each' request payload. I'll read the docs again :) slowly understanding this framework of yours – imp Oct 09 '22 at 11:05
  • no worries, if you break down your question into simpler examples that makes it easier to understand. refer: https://stackoverflow.com/help/minimal-reproducible-example – Peter Thomas Oct 09 '22 at 12:11
  • Promise to get back to this Peter, its going to take me over a week ;( – imp Oct 11 '22 at 13:50
  • 1
    Took a while and I feel silly, buuut I'm back on track thank you Peter! – imp Mar 03 '23 at 06:12