Ask a Question

Javascript equivalent to these Groovy scripts

amf
New Contributor

Javascript equivalent to these Groovy scripts

Below scripts are working fine when I use Groovy, I need same functions to work with JAVASCRIPT in the SOAP UI Pro.

//Get Login URL –
//"Location" is one of the value returned in the response header of step "REST Request1". Need to add this to a Project/Global property which will be refered in subsequent steps
def headerValue = testRunner.testCase.getTestStepByName("REST Request1").httpRequest.response.responseHeaders["Location"][0]
projectProperty = testRunner.testCase.testSuite.project.setPropertyValue( "Login_URL", headerValue.toString() )

//Get Cookie 1 –
//"Set-Cookie" is one of the value returned in the response header of step "Login URL". Need to split this using regex to get the required part
def cookie1 = testRunner.testCase.getTestStepByName("Login URL").httpRequest.response.responseHeaders["Set-Cookie"][1] 
def (var1, cookieOBconsent, var3) = cookie1.split("t=|;")
log.info cookieOBconsent
projectProperty = testRunner.testCase.testSuite.project.setPropertyValue( "cookie1", cookieOBconsent.toString() )

For the 1st set of code, I have tried below Javascript -

//Get Login URL -
var headerValue = context.expand(testRunner.getTestCase().getTestStepByName("REST Request").httpRequest.response.responseHeaders["Location"]()); 
log.info(headerValue);

But it returns a pop up message containing the complete response string including the header "Location" and an error. The log.info dosent work. Below is the contents of pop up window (masked for confidential area)

org.mozilla.javascript.EcmaError: TypeError: Cannot find function Location in object Access-Control-Expose-Headers : APIm-Debug-Trans-Id, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-Global-Transaction-ID Access-Control-Allow-Origin : * X-Backside-Transport : FAIL FAIL Connection : close location : https://^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #status# : HTTP/1.1 302 Found Content-Type : application/json . 

 

 

 

4 REPLIES 4
Nastya_Khovrina
Moderator

Re: Javascript equivalent to these Groovy scripts

Hi,

 

What is the reason of using JavaScript instead of Groovy?


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
amf
New Contributor

Re: Javascript equivalent to these Groovy scripts

We have some other automation which needs only Javascripts to be used. As the tool supports only one (either Groovy or Javascript) at any given point in time(?) for single project, need other automation in Groovy to be converted to Javascript.

amf
New Contributor

Re: Javascript equivalent to these Groovy scripts

Can you help on this please?

TanyaYatskovska
Community Manager

Re: Javascript equivalent to these Groovy scripts

Hi @amf,

 

Based on what I see, the groovy script is much popular for API tests because of some advantages, like getting access to the object model. This allows users to create powerful scripts. For ReadyAPI users, we recommend that they use Groovy. Here is why:

https://support.smartbear.com/readyapi/docs/configure/plugins/dev/object-model.html

 

We support the JavaScript Rhino engine by Mozilla Foundation as well. You can use it. To create scripts on this language, please refer to the engine documentation.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: