When you import a Postman collection into mabl, mabl ensures that different levels of pre- and post-request scripts are imported in the correct order. This article explains how scripts from Postman collections are imported into mabl API test(s).
Comparing scripts in Postman and mabl
Postman and mabl both support running pre-request and post-request scripts:
- Pre-request scripts run before the request is executed.
- Post-request scripts, which are called test scripts in Postman, run after the request is executed.
In both Postman and mabl, these pre-request and post-request scripts can be configured at different levels. To understand how Postman scripts are imported, it’s important to first outline the different script levels. The mapping of Postman script levels to mabl is ultimately determined by the chosen import method.
Postman script levels
| Type of script | Description |
|---|---|
| Collection-level script | Applies to all the requests in a Postman collection |
| Folder-level script | Applies to all requests that are immediate children of that folder. Doesn’t apply to requests in nested folders. |
| Request-level script | Applies to the individual request |
mabl script levels
| Script level | Description |
|---|---|
| Test-level script | Applies to every request in an API request |
| Flow-level script | Applies to every request in an API flow |
| Request-level script | Applies to the individual request |
How Postman scripts are imported into mabl
To ensure that scripts in an imported Postman collection run in the correct order, mabl combines scripts differently depending on whether you import the collection as a single test or whether you import every folder as a separate test.
Importing as a single test
If you import an entire Postman collection as a single test, mabl makes the following updates to preserve the order of scripts:
- Collection-level scripts become one-time API snippets added at the test level so that they execute before every request in the test.
- Folder-level scripts become reusable API snippets and are prepended to every request that is an immediate child of that folder.
Importing as separate tests
If you import folders in a Postman collection as separate tests, each folder with at least one immediate child request becomes a new API test containing those same child requests. mabl makes the following updates to preserve the order of scripts:
- Collection-level scripts are saved as reusable snippets so that they can be reused across all imported API tests.
- Folder-level scripts are saved as one-time snippets.