cancel
Showing results for 
Search instead for 
Did you mean: 

I am facing an issue on saving the value from response to a property using assertion

SOLVED
Highlighted
Visitor

I am facing an issue on saving the value from response to a property using assertion

My Response

 

HTTP/1.1 201 Created
Date: Fri, 09 Oct 2020 15:29:59 GMT
Content-Type: text/plain
X-Application-Context: provisioningContext,AESPassword:oidc,multiTenant:8086
TraceID: f81edfd6-a7a1-41d4-b3aa-602287523f07
Content-Length: 32

8a74833d746c689a01750dfbada4709f

 

I need to save 8a74833d746c689a01750dfbada4709f to a property called Id in the testcase, so that i can use it in the next teststep.

 

Tried -

As there is no name space i couldn't trace the value so used *

 

def gutils = new com.eviware.soapui.support.GroovyUtils( context );
def responseHolder = gutils.getXmlHolder(messageExchange.responseContentAsXml.toString());
def token = responseHolder.getNodeValue("//*:*")

def testCase = messageExchange.modelItem.testCase
testCase.getTestStepByName("Properties").setPropertyValue("id",token);

 

 

I am new to SoapUI so can anyone help me on how to resolve this?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: I am facing an issue on saving the value from response to a property using assertion

Hey @iotmail9 

 

so you just want to save an HTTP header value to a property for later use?

 

I cant see which header the value '8a74833d746c689a01750dfbada4709f' is associated with - when I've done this before I've used either a groovy script or a script assertion as follows:

 

Script assertion option:

//Script assertion uses messageExchange.modelItem rather than testRunner

//Takes one of the elements of the response Header
def value = messageExchange.modelItem.testStep.testCase.testSteps["REST TestStepName"].testRequest.response.responseHeaders["headerName"]

//Read this value into a parameter - writes the header value into the Properties test step
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
groovyUtils.setPropertyValue("Properties", "header",value[0])


//the above grabs the value associated with the 'headerName' header and saves it to the 'header' property within the Properties test step

 

 

Groovy Script option:

//Groovy Script uses testRunner rather than messageExchange.modelItem 

//Takes one of the elements of the response Header
def value = testRunner.testCase.testSteps["REST TestStepName"].testRequest.response.responseHeaders["headerName"]

//Read this value into a parameter - writes the header value into the Properties test step
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
groovyUtils.setPropertyValue("Properties", "header",value[0])


//the above grabs the value associated with the 'headerName' header and saves it to the 'header' property within the Properties test step

 

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

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: I am facing an issue on saving the value from response to a property using assertion

Hey @iotmail9 

 

so you just want to save an HTTP header value to a property for later use?

 

I cant see which header the value '8a74833d746c689a01750dfbada4709f' is associated with - when I've done this before I've used either a groovy script or a script assertion as follows:

 

Script assertion option:

//Script assertion uses messageExchange.modelItem rather than testRunner

//Takes one of the elements of the response Header
def value = messageExchange.modelItem.testStep.testCase.testSteps["REST TestStepName"].testRequest.response.responseHeaders["headerName"]

//Read this value into a parameter - writes the header value into the Properties test step
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
groovyUtils.setPropertyValue("Properties", "header",value[0])


//the above grabs the value associated with the 'headerName' header and saves it to the 'header' property within the Properties test step

 

 

Groovy Script option:

//Groovy Script uses testRunner rather than messageExchange.modelItem 

//Takes one of the elements of the response Header
def value = testRunner.testCase.testSteps["REST TestStepName"].testRequest.response.responseHeaders["headerName"]

//Read this value into a parameter - writes the header value into the Properties test step
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
groovyUtils.setPropertyValue("Properties", "header",value[0])


//the above grabs the value associated with the 'headerName' header and saves it to the 'header' property within the Properties test step

 

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

View solution in original post

Highlighted
Community Manager

Re: I am facing an issue on saving the value from response to a property using assertion

Thanks a lot Richie!

 

@iotmail9 is this what you were looking for?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements