Forum Discussion
Whats the reason you need groovy? Where you say [quote: Im creating a groovy script to generate a POST json to include in a REST web service step] i dont understand why youre not using the OTB functionality to do this.
Later on in your post you seem to state you want the groovy to process and reports certain datasource stats.
Also you mentioned ypuve found some groovy you thought might work if updated...f you have some groovy, even if it doesnt work its alwaysbest to add it to your post so the groovy scripters on the forum (not me!) will have a better understanding of where youre at in regards to progress.
Example csv and request payload can only help too (although i always forget this bit too!)
Cheers,
rich
- Ludo151019666 years agoContributor
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
- TanyaYatskovska6 years agoSmartBear Alumni (Retired)
- New2API6 years agoFrequent Contributor
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
- 22 days ago