Overview
JetClient provides powerful scripting capabilities that allow you to automate tasks, validate responses, and create complex testing scenarios. Scripts can be added to requests, folders, or exist as standalone entities.
Key Features
JetClient scripting enables you to:
- Write automated tests and assertions for API responses
- Dynamically set and modify variables during execution
- Chain multiple requests and scripts together
- Control request execution flow and implement conditional logic
- Generate or transform data programmatically
- Create reusable logic for common operations
Script Types and Execution Order
JetClient supports several types of scripts. All types except standalone scripts execute at specific stages of the request lifecycle:
Init Script
- Executes once per run before any other scripts
- Used for defining global helper functions, performing one-time setup operations, initializing global variables and test data
Pre-request Scripts
Pre-request scripts execute before sending a request in the following hierarchical order:
- Collection (top-level folder) pre-request script
- Intermediate folders’ pre-request scripts (from collection to request’s folder)
- Request folder’s pre-request script
- Request’s pre-request script
This hierarchical execution allows for proper inheritance and override of setup logic. Pre-request scripts are commonly used to:
- Set dynamic variables
- Modify request parameters, headers, or body
- Generate authentication tokens or signatures
- Log or prepare data before execution
Post-response Scripts
Post-response scripts execute after receiving a response, following a similar hierarchical order:
- Collection (top-level folder) post-response script
- Intermediate folders’ post-response scripts (from collection to request’s folder)
- Request folder’s post-response script
- Request’s post-response script
This structure enables cascading response handling and validation. Post-response scripts are typically used to:
- Validate response data
- Extract values from responses for use in future requests
- Store response data into variables
- Handle errors or implement retry logic
- Chain additional requests based on response content
Standalone Scripts
Standalone scripts are independent entities that can be run manually using Test Runner or called from other scripts using jc.runScript
or jc.runScriptAsync
functions.
Standalone scripts are particularly useful for:
- Creating comprehensive test suites by orchestrating multiple requests
- Implementing shared functionality that can be reused across different scripts
- Building complex testing scenarios with custom logic
- Performing setup or cleanup operations
Further Reading
To learn more about specific aspects of JetClient scripting, refer to these dedicated sections:
- JetClient Library - API reference of JetClient Library
- Variables - Learn how to work with variables in your scripts
- Write Tests - Discover how to create effective API tests
- Built-in Libraries - Explore the pre-included libraries
- External Libraries - Learn how to use additional libraries