1

I am looking for a way to use data driven in combination with an external request file.

So my feature file looks like this:

Feature: EPOS UNIT test - GetSpendingLimit

  Background:
    * url 'http://xxx-yyy-zzz'
    * def GetSpendingLimit_request = read('classpath:examples/EPOS/request/GetSpendingLimit-dd-request.xml')
    * def GetSpendingLimit_data = read('classpath:examples/EPOS/data/GetSpendingLimit.csv')

  Scenario Outline: GetSpendingLimit External Request Datadriven
    Given request GetSpendingLimit_request
    When soap action 'TotalAmount'
    Then status 200
      # define a variable to check the response
    * def total_amount = /Envelope/Body/GetSpendingLimitResponse/spendingLimit/totalAmount
      # to print the result to the report
    * print '\nTotal Amount is: ', total_amount

    Examples:
       |read('classpath:examples/EPOS/data/GetSpendingLimit.csv')|

And my request looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://xxx-yyy-zzz/GetSpendingLimit/Request" xmlns:com="http://xxx-yyy-zzz/Common" xmlns:ser="http://xxx-yyy-zzz/Common/ServiceContext">
    <soapenv:Header/>
    <soapenv:Body>
        <req:GetSpendingLimitRequest>
            <ser:productServiceContext>
                <ser:conversationId>GetSpendingLimit_1_1</ser:conversationId>
                <ser:deviceTypeId>1</ser:deviceTypeId>
                <ser:entityId>nl</ser:entityId>
                <ser:product>
                    <ser:id><product-id></ser:id>
                </ser:product>
                <ser:user>
                    <ser:id><user-id></ser:id>
                </ser:user>
            </ser:productServiceContext>
        </req:GetSpendingLimitRequest>
    </soapenv:Body>
</soapenv:Envelope>

Notice that I have added product-id and user-id as variable which should be replaced by data driven input from the csv. But I get the following error:

[Fatal Error] :10:43: The element type "product-id" must be terminated by the matching end-tag "</product-id>".
11:35:18.404 [main] ERROR com.intuit.karate - src/test/java/examples/EPOS/GetSpendingLimit-external-request-datadriven.feature:5
* def GetSpendingLimit_request = read('classpath:examples/EPOS/request/GetSpendingLimit-dd-request.xml')
js failed:
>>>>
01: read('classpath:examples/EPOS/request/GetSpendingLimit-dd-request.xml')
<<<<

I have tried the request in the feature file and this works fine. But the request in external file fails.

sst0107
  • 23
  • 2

1 Answers1

0

The error is clearly saying the XML is not well-formed. Use some XML tool and fix it, for e.g. something like this: https://www.freeformatter.com/xml-formatter.html

For example this should be:

<ser:id><product-id/></ser:id>
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Yes, I understand, but that was not the question. I want to pass on a variable from a csv into the external request. So when the xml is in the feature file, you use . So I did the same for the external request. But than I got the error about the wrongly formatted xml. Is it possible to combine an external csv and external request (both in seperate files)? – sst0107 Nov 24 '21 at 12:02
  • @sst0107 if this does not answer your question, please assume that what you want is not supported by karate: https://stackoverflow.com/a/62449166/143475 – Peter Thomas Nov 24 '21 at 13:42