cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript equivalent to these Groovy scripts

Highlighted
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
Highlighted
Moderator

Re: Javascript equivalent to these Groovy scripts

Hi,

 

What is the reason of using JavaScript instead of Groovy?



Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
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.

Highlighted
New Contributor

Re: Javascript equivalent to these Groovy scripts

Can you help on this please?

Highlighted
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 Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Filtering data retrieved from a DataSource

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors