torelucid.blogg.se

Postman variables
Postman variables




postman variables

Set a variable in the script according to the predetermined scope of the variable through pm.t("variable_key", "variable_value") method or pm.t("variable_key", "variable_value ") method, this method requires the key and value of the variable to set the variable. Variables can be initialized in scripts and placed in specific scopes You can initialize and retrieve these variables in different ways. Because these parts are written by JavaScript. Variables can be used in pre-request and test scripts. Step 1: Enter the collection settings pageĮxpand Access variables through scripts (scripts) Valid for all requests under this collection and its subfolders After everything is set, click to run the collection

postman variables

Note: After uploading the local data file, you also need to select the data file type in the "Data File Type" column. At this time, the file should be saved as a file in UTF-8 format If there is Chinese in the text, garbled characters will be displayed. The name of the parameter must be written in the first line of the fileĢ.

#Postman variables code#

Step 2: Add code in the Pre-request Script areaġ. Step 1: Build the request (determine which part needs to use variables) But if is set as a variable, such as Įxample : get method uses local variablesĮxample: Post method using local variablesĭata variables: Get variable data by importing external data files (json/csv/TXT files) If one day becomes so.com, if no variables are used, the URLs of the above three API requests need to be modified. In addition, if you want to change the value, you can affect the value of the variable by changing the variableįor example: Suppose there are 3 API requests using the same domain Variables allow the same value to be reused in multiple places, thus keeping the code independent. Simply put, a variable is a symbol that can take on different values Variables can be accessed by variable name. In computer languages, it refers to an abstract concept that can store calculation results or represent values. With the help of variables, Postman can separate business logic from test data, which helps users create robust test casesĪ variable is a concept derived from mathematics.






Postman variables