Forum Discussion

kasunrama's avatar
kasunrama
Occasional Visitor
4 years ago

Get Response Headers from script

Hi, I'm trying to execute soapui tests from my junit tests (junit integration) How can I get the response headers for assertion? I can get the raw response property from test step, but is there any...
  • TNeuschwanger's avatar
    4 years ago

    Hello kasunrama,

     

    I have been successful at retrieving header values from a response by using the HarResponse of a service response.  I don't know if I understand your question completely, but the following is some groovy script code you can hack from to see if anything could work for you to capture a header value from a response.

     

    def harResponse = context.expand( '${HTTP Request GET authentication-service#HarResponse}' )
    
    log.info ' harResponse "' +  harResponse;
    def jsonHarResponse = new groovy.json.JsonSlurper().parseText(harResponse);
    log.info 'jsonHarResponse=' + jsonHarResponse;
    //jsonExpected = 'Bundle';
    //assert jsonContent.resourceType == jsonExpected, 'Expected "' + jsonExpected + '" but got "' + jsonContent.dbResult + '"';
    
    
    def headerResponseList = chooseNewResourceIdFromResponse();
    
    log.info ('Transform Response Headers:');
    log.info ('');
    subjectToken = '';
    headerResponseList.each {
       log.info ('   ' + it);
    
       if (it.contains('Subject-Token: ')) {
          subjectTokenList = it.tokenize(': ');
          subjectToken = subjectTokenList[1];
          subjectTokenList .each {
             log.info (' token  ' + it);
          };
       };
    };
    log.info ('');
    
    testRunner.testCase.testSteps["Properties"].setPropertyValue( "subjectToken", subjectToken);

     

    Regards,

    Todd