Using Variables in LPS
Variables enhance the flexibility of test scenarios by allowing dynamic data to be injected into requests. They can be predefined or generated during the test and are useful for:
- Storing values captured from responses.
- Referencing external data sources like CSV files or JSON configurations.
- Creating parameterized test cases.
- Building dynamic requests using runtime values.
To use a defined variable, prefix it with $ or use ${} for complex placeholders.
For example:
${csvData[0,$counter(start=0, reset=10)]}
Example
name: variablesTest
variables:
- name: responseTime
value: $randomnumber(min=100, max=500)
rounds:
- name: VariableExampleRound
numberOfClients: 2
arrivalDelay: 5000
iterations:
- name: UseVariable
mode: R
requestCount: 200
httpRequest:
url: https://example.com/resource/$responseTime
httpMethod: GET
Variable Types
String Family
String, QString, Json, QJson, Xml, QXml, Csv, QCsv
Note: Q* types return quoted values for safe string comparisons.
Numeric Types
Int, Float, Double, Decimal
Boolean
Boolean - true/false values
You can also attach an optional regex to validate or filter the value after it is assigned.
Resolution Order
Variables are resolved in the following order: Session → Global.
Session variables take precedence over global variables with the same name.