Forum Discussion

heathen462's avatar
heathen462
New Contributor
12 years ago

responseHeaders not available in LoadTest?

I've searched all over, and please forgive me if the answer is already out there, but I cannot find the solution to this issue.

I have a RESTful API that uses cookie authentication. Using the normal TestCase runner, I have a groovy transfer script that retrieves the "Set-Cookie" param from the authentication login request response headers, and applies this cookie to the rest of the requests in the test case.

When I attempt to run a load test, the transfer step ALWAYS fails, stating that responseHeaders does not exist. I'm at a complete loss, and have tried everything from keeping the http session alive to passing the username/password. Nothing works.

How do I retrieve/manipulate the response headers in a load test?

This is the transfer step:

// You can get http header of "Set-Cookie" from "login" test step in soapUI
def setCookie = testRunner.testCase.testSteps["authentication-login"].testRequest.response.responseHeaders["Set-Cookie"]

// if you want to get PHPSESSID=value, use this regular expression
def re = /(PHPSESSID=[A-Za-z0-9]+)/
def matcher = ( setCookie =~ re )
def cookie = matcher[0][0]

// Iterate through all test steps and add the session cookie to the headers.
for ( tstep in testRunner.testCase.testSteps ) {
testStepName = ( tstep.key )

//assuming your login request is entitled "login" and your transfer groovy step is entitled "TransferAuthCookie"
if ( testStepName != 'authentication-login' && testStepName != 'TransferAuthCookie') {
testRunner.testCase.testSteps[testStepName].testRequest.requestHeaders["Cookie"] = cookie
}
}


it is failing to on

def setCookie = testRunner.testCase.testSteps["authentication-login"].testRequest.response.responseHeaders["Set-Cookie"]


as testRunner.testCase.testSteps["authentication-login"].testRequest.response.responseHeaders doesn't exist in LoatTest, apparently.

Any assistance or just a "n00b, the answer is here" is greatly appreciated. I've already spent hours on this and am at my whit's end.
  • heathen462's avatar
    heathen462
    New Contributor
    I actually solved this after discovering and enabling the global setting "Authenticate Preemptively", in combination with "Maintain HTTP Session" at the test case level.

    The issue still stands, however, as to why
    testRunner.testCase.testSteps["request_name"].testRequest.response.responseHeaders
    is not within scope in a load test. Logically, I would think this would still be accessible, as it is still running the test case...though I suspect the scope is changed, as loadTestRunner is used in lieu of testRunner? IMHO, this behavior should be corrected, perhaps by having loadTestRunner inherit testRunner, or wrapping testRunner's methods within loadTestRunner...?