Forum Discussion

iotmail9's avatar
iotmail9
Visitor
5 years ago

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-a7...
  • richie's avatar
    5 years ago

    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