cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy and Java scripts in one project

Contributor

Groovy and Java scripts in one project

I have a project need where i need to perform some REST calls in a groovy project but then in the same project need to call some REST API's which has some java script in it for pre setup ....can they both be in the same project as per soap ui documentation we can have only one language in the project properties with the script language set to groovy or Javascript ?

 

So this would be like a nested project where i need both groovy and Javascript to work in the same project 

39 REPLIES 39
Highlighted
Community Hero

Re: Groovy and Java scripts in one project

Hey,

Id welcome an answer to this too!

As @ameesh1984 states, the help info appears to indicate the use of groovy or javascript is mutually exclusive at project level.....it doesnt appear that you can run both script command interpeters in the same project.
HOWEVER, this appears to contradict the instructions defined for OAuth v2.0 automatic token retrieval (javascript) along with checking if the OAuth 2.0 token has expired or not (groovyscript).

Also, if you think about it, the help indicates you cant run both at the same time but if you need OAuth v2.0 in your project so you need to use javascript for auto token retrieval, doesnt this mean that you cant have ANY other groovyscript in your project? Surely thats madness!?!?!?! Very few of my projects now dont use at least some groovy snippets.

Would welcome any guidance on this please!

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Groovy and Java scripts in one project

As you pointed rightly, either groovy or java script is supported, but not both.

If you provide more details, then it may help to see if the same can be achieved in groovy itself.


Regards,
Rao.
Highlighted
Contributor

Re: Groovy and Java scripts in one project

Suppose I need to do the following

1. My pre setup script has some JS code that needs to run and do some initial setup
2. My actual project is Rest based and has some assertions via groovy asserts

Can this be done in one project how would I do this ?

Here is some of the JS code in this postman collection in the pre setup script

https://github.com/liupeirong/cosmosdb-postman-collection
Highlighted
Contributor

Re: Groovy and Java scripts in one project

If I have java code equivalent for the JS pre setup script would that work in groovy test step , then I can leave my project as groovy and add those java pre setup steps in it
Highlighted
Community Hero

Re: Groovy and Java scripts in one project

What does that pre-setup script does?


Regards,
Rao.
Highlighted
Contributor

Re: Groovy and Java scripts in one project

Attached it 

 

It basically takes postman variables like host , keys etc  and does some stripping or modfications to it 

 

It was basically meant for pre setup before the test 

 

I am looking to convert this to groovy so that it will work in my existing soap ui project

Highlighted
Contributor

Re: Groovy and Java scripts in one project

 
Highlighted
Contributor

Re: Groovy and Java scripts in one project

Any simple way to convert this to groovy ?

Highlighted
Community Hero

Re: Groovy and Java scripts in one project

Hey @ameesh1984,

I had a search for this about 2 years ago and couldnt find anything. I just searched and it appears there may be a couple of js to groovy converters but i doubt you can just paste the js code in, hit convert and out comes some spffy groovy code that works right away.
I had a quick look at the js and it doesnt look that complicated (well...i could read it, which should tell you how basic it appears).
If i were you id try and identify what is going on (e.g. "vars attribute" is defining new variable in js, which is like "def attribute" in groovy) and then search for the groovy equivalent.
Im even tempted to have a go at this myself, but i dont want you to rely on me cos my coding bites, so i suggest having a to yourself unless one of the scripters has js AND groovy

Ta

Rich

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors