1

The value of order_contents is passed from a CSV file defined in scala file. order_contents in the CSV file is defined as "read('classpath:data/XML-Order.txt')" XML-Order.txt contains a string that is in XML format. Due to some limitations, I want to read it as string. :)

Feature: checkOrder

 Background:
 Given url getOrder.URL
 * def contents = __gatling.order_contents

@checkOrder
 Scenario: checkOrder
* string orderContents = contents
* print orderContents

When running, the print statement shows only read('classpath:data/XML-Order.txt') as a string but not the contents of the string

BUT By hardcoding the path, it will achieve the result as what I have expected.

Feature: checkOrder

 Background:
 Given url getOrder.URL
 * def contents = __gatling.order_contents

@checkOrder
 Scenario: checkOrder
* string orderContents = read('classpath:data/XML-Order.txt')
* print orderContents

When running, the print statement will shows the XML string that is in XML-Order.txt file.

Also tried to do this

 * def test = <contents>
 * string value = test

But I am getting the below error when printing org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 24; XML document structures must start and end within the same entity.

But I want to implement a more dynamic way of defining the data via CSV file. Any help is appreciated.

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
Monster
  • 35
  • 4

1 Answers1

0

2 suggestions.

Just have the path of the file held in __gatling.order_contents - e.g: classpath:data/XML-Order.txt

Then this will work, and note that there is a karate.readAsString() option:

* def orderContents = karate.readAsString(__gatling.order_contents)

Else, write a Java utility to do exactly what you want: https://stackoverflow.com/a/54593057/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Great! This solution worked. Why din i think of this. * string orderContents = karate.readAsString(__gatling.order_contents) * print orderContents – Monster May 27 '23 at 16:38