Ask a Question

How to write a groovy script for a REST project

SOLVED
dou
New Contributor

How to write a groovy script for a REST project

Hi,

 

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.

 

DOU

8 REPLIES 8
Radford
Super Contributor

Is there a reason that you have to use Groovy script? Have you seen the following tutorial?

 

http://readyapi.smartbear.com/soapui/rest/intro/getting_started

 

 

dou
New Contributor

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 :

http://readyapi.smartbear.com/structure/parameters/styles/start

 

Do you know how can i add Rest parameter QUERY, TEMPLATE, HEADER, MATRIX, PLAIN with groovy ?

Radford
Super Contributor

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.

nmrao
Champion Level 3

Why reinventing the wheel being a beginner. You may start using the existing feature, once you become familiar to it, you automatically do things on your own.

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.


Regards,
Rao.
nmrao
Champion Level 3

Looks I missed the conversations below.

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.


Regards,
Rao.
dou
New Contributor

Hi,

 

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. 🙂

 

Thanks !

sanj
Super Contributor

In case you missed the webinar

This has tutorial on how to do what you wana do.

I am in the same boat!

 

https://community.smartbear.com/t5/SoapUI-NG/SBA-Elective-Class-Advanced-Groovy-Scripting-Recap-amp-...

 

 

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

 

 

cancel
Showing results for 
Search instead for 
Did you mean: