cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Environment Rest Services properties from a Groovy script.

Highlighted
Occasional Contributor

Setting Environment Rest Services properties from a Groovy script.

hello,

I was curious if I could SET Rest Service, properties(name,endpoint) in the Environments section in SoapuiPro with a Groovy Script.  I was only able to find information regarding retrieving information in the Environment with a Groovy Script.  (see photo)

15 REPLIES 15
Highlighted
Community Hero

Yes you can. Environment variables are just normal SoapUi properties.


If my answer helped please click on the 'Accept as Solution' button.
Highlighted
Occasional Contributor

Can you please give me an example Groovy script for Setting the evironment properties or point me to the location in the soapuiapi.org?

Highlighted

Hey, I am kinda on the run and I don't have my work laptop with me. I will try to help you with some info though later today or tomorrow.


If my answer helped please click on the 'Accept as Solution' button.
Highlighted

Here is a late response... So I quickly looked at this and it is much harder than I initially thought. The endpoint and the name of the service are not saved as project properties so it is more difficult to change them.

So far I have only managed to change the service name in an environment.

Another solution would be to not change the endpoint itself but to assign to the endpoint a project property. Then you would change that project property depending on the environment. The only drawback of this is that you won't be able to xhange the service name...


If my answer helped please click on the 'Accept as Solution' button.
Highlighted
Occasional Contributor

@Lucian

Thank you for responding to the question.  I must admit, I was dissapointed initially thinking I would never get a response.  You are correct with the thought that the endpoints and the name of the services are not saved as project properties, so I am unable to find a solution to set them.  

In case anyone else sees this and wonders what the solution was.  My work around for this problem is to within the Endpoint reference multiple soapui project properties, (whose values will be set by a Project.Run Groovy script).  That way if a change is required it will only need to be changed in one place (The Groovy Script).

It will look something like this:
Endpoint:
https://${Project#ServiceName}-${Project#branchName}.com

Highlighted

I am pretty sure it can be done directly by working with the rest service but I am not sure how. The service object has a method called 'setEndpoint' (I thought I did it when I saw it) but it only takes an endpoint object as parameter - so you cannot pass a string url for instance...

I will probably look more into it because I got very curious about this but I can't promise anything. I am quite busy lately.


If my answer helped please click on the 'Accept as Solution' button.
Highlighted

Still didn't manage to do it.

 

@msiadak, I dare you!



If my answer helped please click on the 'Accept as Solution' button.
Highlighted

Let me see what I can figure out. 🙂 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
Occasional Contributor

Did you get it to work!? 🙂

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors