The problem: WS.getElementPropertyValue() only parses the response body (JSON/XML), not HTTP headers. Since your Authorization token is in the response headers, this method will never find it.
Solution: Use response.getHeaderFields() Instead
**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 GlobalVariable for use in subsequent requests
GlobalVariable.authToken = token**
Alternative: Handle Case Sensitivity + Null Checking
**def response = WS.sendRequest(findTestObject('Object Repository/LoginRequest'))
WS.verifyResponseStatusCode(response, 200)
Map headerFields = response.getHeaderFields()
// Handle case-insensitivity (HTTP headers are case-insensitive, but Java Map is case-sensitive)
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()) // Debug: see all headers
}
Key Differences: Headers vs Body
| What You Need |
Method to Use |
Example |
| Response Headers |
response.getHeaderFields() |
Authorization, Content-Type, Set-Cookie, Location |
| Response Body (JSON/XML) |
WS.getElementPropertyValue() |
{"status": "success"}, nested JSON data |
Using the Token in Subsequent Requests
Once extracted, use the token in your next API request:
// Option 1: In Test Object HTTP Header tab**
// Set: Authorization: ${authToken}
// Option 2: Programmatically
def nextRequest = findTestObject('Object Repository/NextRequest')
nextRequest.setHttpHeader('Authorization', GlobalVariable.authToken)
def nextResponse = WS.sendRequest(nextRequest)**
Debug Tip: Print All Headers
If Authorization returns null, debug by printing all available headers:
**`println("All headers: " + headerFields.keySet())`**
This helps you see the exact header name (it might be `authorization` lowercase or something else).
**Bottom line:** Use `getHeaderFields()` for headers, `getElementPropertyValue()` for body—they're separate concerns in HTTP responses