Help! getElementPropertyValue() is ignoring my response headers in Katalon?

Problem Analysis

You’ve correctly identified the issue: WS.getElementPropertyValue() is designed exclusively for parsing the response body (JSON/XML), not HTTP headers. Headers and body are separate concerns in HTTP responses, and Katalon provides different methods to access each.

The reason your code returns null is that getElementPropertyValue() searches the JSON body structure, not the HTTP header metadata. Since your Authorization token is in the response headers, this method will never find it.

Solution

Use response.getHeaderFields() to extract headers as a Map:

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

// 1. Send the request
def response = WS.sendRequest(findTestObject('Object Repository/LoginRequest'))

// 2. Verify status code first
WS.verifyResponseStatusCode(response, 200)

// 3. Extract headers as a Map
Map headerFields = response.getHeaderFields()

// 4. Get the Authorization token from headers
def token = headerFields.get('Authorization')

// 5. Print for verification
println("Token: " + token)

// 6. Store in a variable for use in subsequent requests
GlobalVariable.authToken = token

Alternative approach with null checking:

def response = WS.sendRequest(findTestObject('Object Repository/LoginRequest'))
WS.verifyResponseStatusCode(response, 200)

Map headerFields = response.getHeaderFields()

// Handle case-sensitivity and null values
def token = headerFields.get('Authorization') ?: headerFields.get('authorization')

if (token != null) {
    println("Successfully extracted token: " + token)
    GlobalVariable.authToken = token
} else {
    println("ERROR: Authorization header not found!")
    println("Available headers: " + headerFields.keySet())
}

Key Considerations

1. Header Name Case Sensitivity
HTTP headers are technically case-insensitive, but Java’s Map is case-sensitive. If headerFields.get('Authorization') returns null, try lowercase: headerFields.get('authorization'). You can also print all available headers to debug:

println("All headers: " + headerFields.keySet())

2. Using the Token in Subsequent Requests
Once extracted, use the token in your next API request by setting it as a header:

// In your next API request's HTTP Header tab, set:
// Authorization: ${authToken}

// Or programmatically:
def nextRequest = findTestObject('Object Repository/NextRequest')
nextRequest.setHttpHeader('Authorization', GlobalVariable.authToken)
def nextResponse = WS.sendRequest(nextRequest)

3. Response Header vs. Response Body

  • Headers (use getHeaderFields()): Authorization, Content-Type, Set-Cookie, Location, etc.
  • Body (use getElementPropertyValue()): JSON/XML data like {"status": "success"}

4. Best Practice for API Testing
According to Katalon’s official best practices, always verify both status code AND headers:

def response = WS.sendRequest(findTestObject('LoginRequest'))

// Verify status
WS.verifyResponseStatusCode(response, 200)

// Verify Content-Type header
Map headers = response.getHeaderFields()
WS.verifyElementPropertyValue(response, 'Content-Type', 'application/json')

References