How to write a groovy script for a REST project
I am a beginner with groovy script and Rest project.
I read some RESt and groovy script blog, and subject but, i don't know how to begin.
I know :
- how to import a REST project with SOAP UI
- to execute a request, we need to add a Resource, a method, and/or a path param, request param and/or a body.
So how to add all theses parameters correctly with groovy script ?
Is there some kind of Library ? API ?
Best Regards and thanks for your help.
Solved! Go to Solution.
Is there a reason that you have to use Groovy script?
Yes. I need to know how to build/ execute a Rest Request using groovy script.
Have you seen the following tutorial?
No, i didn't see it. Thank you !
I have found this link :
Do you know how can i add Rest parameter QUERY, TEMPLATE, HEADER, MATRIX, PLAIN with groovy ?
Sorry, I'm not sure if I'm the right person to help as I don't have detailed knowledge of building and executing REST requests via Groovy (I tend to stick to using the built in test steps and only dropping into Groovy only when I need extra functionality).
A quick look at the REST test step shows its a RestTestRequestStep. This class has various methods for adding parameters, though I have not had to do this myself so can not comment further. In case I mis-understood your last message, if you are wanting to set already existing poperties this page may help.
Hopefully, somebody else with more detailed knowleddge of building REST requests via Groovy can help.
I suggest you to get familiar with tool by spending time, exploring it while having the privilege to enjoy the existing features.
Or is there any constraint that you have so that things to need in such an order? This is just to know your use case.
You may use the link provided by @Radford.
We have a great community, you can always come back and post your specific questions. And there are may good people will help the community.
Have good time.
You mentioned, "Yes. I need to know how to build and execute Rest using groovy"
You may need to spend time to understand first how things works.
If there is a ladder, there are steps, climb one by one. Can't reach from first step to top step in Single step.
For every thing there will be a learning curve.
I could not understand that If you just wanted to do it in groovy, then why you Ready API was choosen.
Sorry for my late response.
Indeed, you are right nmrao.
So in this way, i tried to use Get, Delete, Post, put etc method using SOAP UI to understand better how does it works.
Now my groovy script has nearly been achieved. 🙂
In case you missed the webinar
This has tutorial on how to do what you wana do.
I am in the same boat!
def responseAsString = messageExchange.modelItem.testStep.testRequest.response.contentAsString def jsonResponse = new groovy.json.JsonSlurper().parseText(responseAsString) //log.info(jsonResponse.some.json.element) assert "EXPECTED_VALUE_OF_json.element" == jsonResponse.some.json.element