Correlation in LoadRunner: Complete Guide with Syntax, Examples, and Best Practices
If you’re working with LoadRunner performance testing, one concept you must master is correlation. Without proper correlation, your scripts fail during replay, causing delays in test execution and inaccurate performance results.
This comprehensive guide explains:
- What correlation is in LoadRunner
- Why correlation is required
- Types of correlation (automatic & manual)
- How to identify dynamic values
- How to apply correlation in LoadRunner scripts
- Syntax, examples, and key terminologies
Let’s break it down step by step.
⭐ What Is Correlation in LoadRunner?
Correlation in LoadRunner is the process of capturing dynamic values returned by the server during runtime and reusing them in subsequent requests.
These values change every time a user interacts with the application. Hardcoding them causes replay failures.
Common dynamic values include:
- Session IDs
- Authentication tokens
- ViewState / CSRF tokens
- Cookies
- Request IDs
- Timestamps
- GUIDs
Correlation ensures your script behaves like a real user, making your performance test accurate and reliable.
⭐ Why Is Correlation Required in LoadRunner?
Modern applications generate dynamic values for:
- Security
- Session management
- Preventing replay attacks
- Data integrity
If your script uses outdated or hardcoded values, the server rejects the request, causing errors like:
- HTTP 401 Unauthorized
- HTTP 403 Forbidden
- Session timeout
- Invalid token
Correlation fixes these issues by capturing fresh values during execution.
🔥 Types of Correlation in LoadRunner
LoadRunner supports two main correlation methods.
- Automatic Correlation
LoadRunner automatically detects dynamic values based on predefined rules.
When to use:
- Standard web applications
- Quick script creation
- When correlation rules already exist
Pros:
- Fast
- Beginner‑friendly
Cons:
- May miss custom tokens
- Sometimes correlates unnecessary values
- Manual Correlation
You manually identify and correlate dynamic values using LoadRunner functions.
When to use:
- Complex applications
- Custom tokens
- When automatic correlation fails
Pros:
- Accurate
- Works for all protocols
Cons:
- Requires expertise
- More time‑consuming
🔍 How to Identify Dynamic Values in LoadRunner
Identifying dynamic values is the most important part of correlation.
Step 1: Record the script twice
Record the same business flow two times.
Step 2: Compare the recordings
Use LoadRunner’s Compare Recording feature.
Look for values that:
- Change between the two recordings
- Appear in server responses
- Are used in later requests
Step 3: Confirm the value is dynamic
A dynamic value usually:
- Appears in server response
- Is required in subsequent requests
- Causes replay failure when hardcoded
Common indicators of dynamic values:
- Long alphanumeric strings
- Tokens like JSESSIONID, CSRFToken, authToken
- Hidden HTML fields
- JSON response values
- Cookies
🛠️ LoadRunner Correlation Syntax with Examples
LoadRunner provides multiple correlation functions depending on the response format.
- web_reg_save_param (Basic Correlation)
web_reg_save_param(
“ParameterName”,
“LB=left boundary”,
“RB=right boundary”,
LAST);
Example:
web_reg_save_param(“SessionID”,
“LB=JSESSIONID=”,
“RB=;”,
LAST);
- web_reg_save_param_ex (Advanced Correlation)
web_reg_save_param_ex(
“ParamName=Token”,
“LB=left boundary”,
“RB=right boundary”,
“Ordinal=1”,
SEARCH_FILTERS,
“Scope=Body”,
LAST);
Example:
web_reg_save_param_ex(
“ParamName=AuthToken”,
“LB=\”authToken\”:\””,
“RB=\””,
“Ordinal=1”,
LAST);
- web_reg_save_param_json (For JSON Responses)
web_reg_save_param_json(
“ParamName=UserID”,
“QueryString=$.data.user.id”,
LAST);
- web_reg_save_param_xpath (For XML Responses)
web_reg_save_param_xpath(
“ParamName=OrderID”,
“Query=//order/id/text()”,
LAST);
📌 Where to Place Correlation Functions in LoadRunner
Correlation functions must be placed before the request that returns the dynamic value.
Example:
web_reg_save_param(“CSRFToken”,
“LB=name=\”csrfToken\” value=\””,
“RB=\””,
LAST);
web_url(“OpenForm”,
“URL=http://example.com/form”,
LAST);
Then use the captured value:
web_submit_data(“SubmitForm”,
“Action=http://example.com/submit”,
“Body=csrfToken={CSRFToken}&data=123”,
LAST);
🧪 Practical Example of Correlation in LoadRunner
Step 1: Capture the dynamic value
web_reg_save_param(“CSRFToken”,
“LB=name=\”csrfToken\” value=\””,
“RB=\””,
LAST);
Step 2: Trigger the request
web_url(“OpenForm”,
“URL=http://example.com/form”,
LAST);
Step 3: Use the captured value
web_submit_data(“SubmitForm”,
“Action=http://example.com/submit”,
“Body=csrfToken={CSRFToken}&data=123”,
LAST);
🧠 Key Terminologies in LoadRunner Correlation
Term Meaning
LB (Left Boundary) Text before the dynamic value
RB (Right Boundary) Text after the dynamic value
Ordinal Position of the value (1, 2, ALL)
Parameter Variable storing captured value
Correlation Capturing and reusing dynamic values
Dynamic Value Value that changes every execution
🏆 Best Practices for Correlation in LoadRunner
- Correlate before replay
- Use meaningful parameter names
- Avoid over‑correlation
- Validate captured values using lr_output_message
- Use JSON/XPath correlation for APIs
- Always compare two recordings
🎯 Conclusion
Correlation is one of the most critical skills in LoadRunner scripting. By understanding how to identify dynamic values and apply correlation correctly, you can create stable, scalable, and accurate performance test scripts.
Leave a Reply