Upload Parameter File
By uploading a CSV parameter file, you can dynamically reference the test data within for use with variables in your scripts.
This way, when the load generator executes this code concurrently, each request can dynamically fetch each row of data from the CSV file to use as request parameters.
Parameter Definition:
The first line of the default CSV is used as the parameter name. In this mode, when PTS reads data, it will skip the first line.
If you don't use the first line of the CSV file as the parameter name, you can uncheck "First Line as Parameter Name" as shown below, then check the row where the parameter file is located, and a parameter name editing box will expand on the page for you to edit the parameter name yourself.
Parameter Usage:
In the code, you can use the parameter name as the variable name to obtain the variable value.
Each VU takes a row of data from the CSV in sequence with each iteration.
After the last row of data in the csv file is read, it will go back to the first row and continue to read in a loop next time.
Combination and Splitting of Parameter Files :
If the stress test concurrency is high, you can check "split file" to split the large file and distribute it to each load generator for use.
Multiple csv parameter files can be uploaded in one scenario for cross-file parameter combination.
Column names (parameter names) in different csv files need to be globally unique.
If different csv files have different row counts, the one with the larger row count is used as the benchmark by default, and the csv file with fewer rows will be automatically replicated to match the row count of the benchmark file, ensuring that the data for each VU iteration is predictable.
Use Parameter File
Simple Mode Scenario
In simple mode scenarios, you can use parameters from the parameter file in the form of ${}
.
Take the following dataset.csv as an example:
MyKey,MyValue
key1,value1
key2,value2
After the upload is complete, it will look as shown below:
Script Mode Scenario
The example code is as follows: Use dataset.get("MyKey")
to obtain the parameter value for the parameter name/column name MyKey
from the CSV file, which serves as the value
in the request body.
import dataset from 'pts/dataset';
export default function () {
const value = dataset.get("MyKey")
const postResponse = http.post("http://httpbin.org/post", {data: value});
console.log(postResponse)
};