You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-12Lines changed: 4 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,16 +25,17 @@ The `utils` functions are logically grouped in nested classes (namespaces) and i
25
25
26
26
*[**Folder level functions**](#folder-level-functions) for setting up tests
27
27
*[**Primary test functions**](#primary-test-functions) for testing request results
28
-
*[**Data validation function**s](#data-validation-functions) for checking data returned from requests
28
+
*[**Data validation functions**](#data-validation-functions) for checking data returned from requests
29
29
*[**Trace functions**](#trace-functions) for trace logging
30
30
*[**General purpose functions**](#general-purpose-functions) for miscellaneour operations
31
31
32
32
## Folder level functions
33
33
Before we get to the overview of the folder level functions, let's summarize how folder scripts work. Folder scripts can be defined for pre-requests and post-requests. For each request in the test collection being executed, Postman first runs pre-request scripts defined in all request parent folders starting from the top level folder. Then Postman runs request's pre-request script, executes the request, and runs all post-request scripts defined in the parent folder just as it did with folder pre-requests. Finally, it runs request tests. And it is worth repeating: this logic gets executed for every request in the test collection. You may not need to run any scripts for any or all folders, which is fine: you simple do not add any code to them; but when you do, you may need to run the code once per test collection execution or for every request in the collection.
34
34
35
-
Use folder level functions to run test or pre-request code attached to test collection folders (but not request scripts).
35
+
Use folder level functions to run test or pre-request code attached to test collection folders (but not request scripts).
36
36
37
37
Folder level functions are grouped under the `utils.run` namespace and include:
38
+
38
39
*[utils.run.once](#utilsrunonce):
39
40
Invokes code in the specified custom inline function once per test collection run.
40
41
*[utils.run.always](#utilsrunalways):
@@ -45,10 +46,8 @@ The following parameters are common to all folder level functions:
45
46
46
47
*`name`:
47
48
Unique name of the folder in the test collection. Because Postman API does not provide a way to determine the current folder, pass a unique name of the folder when calling these functions (the name may need to be unique in the collection) via the `name` parameter.
48
-
49
49
*`process`:
50
50
Inline function containing the code to be executed once or always.
51
-
52
51
*`onerror`:
53
52
Optional function containing code to be executed on error in the `process` function.
54
53
@@ -105,10 +104,8 @@ The following parameters are common to all primary test functions:
105
104
106
105
*`name`:
107
106
All primary test functions require the `name` parameter to hold the unique name of the request (or test). In most cases, instead of hard coding request (or test name), pass the `null` value and the functions will set the name to the global `pm.info.requestName` property holding the name of the request. You should only specify an explicitly defined name if you run multiple tests for a single request, so that you can differentiate between them in the test logs.
108
-
109
107
*`process`:
110
108
Inline function containing the code to be executed (this function is optional for `utils.test.positive` and `utils.test.negative` functions because they already provide the minimal test functionality that may be sufficient for certain cases).
111
-
112
109
*`onerror`:
113
110
The optional error handler that can be handy if you need to implement special logic (like stopping test execution or skipping to a specific test) on operation failure in the default or custom `process` function.
Expected HTTP status code returned in HTTP response (default value: `400`; it is recommended to explicitly set the expected value).
182
-
183
179
*`serviceCode`:
184
180
Optional string value of the property holding error code returned by the HTTP response. By default, the name of the property is expected to be `serviceCode`. To check a different property, add the name followed by the colon(`:`) or equal (`=`) character before the expected value, such as `'errorCode=IllegalOperation'`.
185
181
186
-
187
182
#### Examples
188
183
A negative test that only checks for the default `400 Bad Request` HTTP status code passed in the HTTP response.
189
184
```JavaScript
@@ -483,6 +478,7 @@ Expects the named object property to end with the specified string value.
483
478
Expects the named object property to match the specified regular expression.
484
479
485
480
### Parameters
481
+
486
482
*`data`:
487
483
Data object which string property is being checked.
488
484
*`name`:
@@ -605,16 +601,12 @@ To set the trace level (which will be stored in an environment variable for the
605
601
606
602
*`utils.trace.set.none(pm)`:
607
603
Sets trace level to `0`.
608
-
609
604
*`utils.trace.set.minimal(pm)`:
610
605
Sets trace level to `1`.
611
-
612
606
*`utils.trace.set.default`:
613
607
Same as `utils.trace.set.all(pm)`.
614
-
615
608
*`utils.trace.set.all(pm)`:
616
609
Sets trace level to `2`.
617
-
618
610
*`utils.trace.set.custom(pm, level)`:
619
611
Use this to set any custom trace level (parameter `level` is expected to hold a positive integer value).
0 commit comments