amf
6 years agoNew 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 .