Forum Discussion
Hello rich
Thanks for your answer
Sorry I don't know what OTB means... you have a link or tutorial ?
I have to generate a small json object to use as POST in my REST web service
I'm use to do it in groovy and store a variable in context
for the first time I'm using datasource to read a set of external parameters,for example
TITLE;MINDATE;MAXDATE
TEST;2001/01/01;2010/01/01
TEST1;2010/01/01;2019/01/01
I have created a datasource FILE step named "DataSource" and the csv seems correctly loaded
I'm looping in datasource with datasource loop, seems ok
In my groovy script I need to get the 3 fields for each line, manipulate the data and build a json structure
def jsonAsText = '''{
"field1" : "string",
"field2" : "string",
"field3" : "string",
}'''
def object = slurper.parseText(jsonAsText)
I found some groovy examples to get datasource fields like
def row = testRunner.testCase.testSteps["DataSource"].currentRow;
def thetitle = context.expand( '${DataSource#TITLE}' )
I looking for a full example of FILE datasource usage in groovy
Thanks for your help
Ludovic
Ludo15101966 , if your json payload is simple and small you do not need any groovy script. Instead insert json payload as below in your rest step.
{
"field1" : ${DataSource#Title},
"field2" : ${DataSource#MinDate},
"field3" : ${DataSource#MaxDate},
}
In order to facilitate above json you should configure your datadource as shown in the picture. (I also overlaid csv file for your reference)
Hope this helps.
Thanks.
Related Content
- 8 years ago
Recent Discussions
- 21 days ago