Ask a Question

Get Response Headers from script

SOLVED
kasunrama
Occasional Visitor

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 way I can use the "messageExchange.responseHeaders" from my junit test? 

 

Thank you

4 REPLIES 4
nmrao
Community Hero

Please show what you have tried if that is not working?
Hope are you running the ReadyAPI project? Do you have the assertion in the project / test step?


Regards,
Rao.
nmrao
Community Hero

By the way, not sure the need for running a junit tests while the same project can be run from commandline using testrunner utility.


Regards,
Rao.
sonya_m
SmartBear Alumni (Retired)

Hi @kasunrama ! Did you manage to solve this?

If not, please provide us with more details!


Sonya Mihaljova
Community and Education Specialist

TNeuschwanger
Community Leader

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

cancel
Showing results for 
Search instead for 
Did you mean: