Forum Discussion

headphonebounty's avatar
headphonebounty
New Contributor
2 years ago

Reading DataSource Items in a Script following a JSON

Hi guys,

 

I have a REST Request that is a JSON. I am using a datasource to input various values into the request. This is in the format as so -

 

${DataSource#Postcode}

 

If I look in the raw request message, this is working fine and populating from the DataSource. However when I try and reference the request message in a property script -

 

def jsonrequest = testRunner.getTestCase().getTestStepByName("RESTRequest").getHttpRequest().getRequestContent()

 

I get this error -

 

groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is '$' with an int value of 36
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 4333

 

It appears that it is not referencing the request containing the values from the datasource, but rather the raw text. How can I fix this? I've used this method successfully in XMLs before.

1 Reply

  • headphonebounty 

    If you use property expansion to get the request content, do you get an error. It would look something like
    def jsonrequest =  context.expand( '${TestStepName#Request}' )
    or
    def jsonrequest =  context.expand( '${TestStepName#RawRequest}' )

    You can use the GetData option within the script to build that for you