- Resetting a user’s onboarding in the backend via JS code
- Generating a random email to be used by the Autosana agent via Python code
- Returning a magic link or OTP code from your server for Autosana to use in the flow via a cURL request
- Mocking audio or video input by hitting an endpoint on your server via TypeScript code
- Setup Hooks: Run before suites or flows start. Great for providing context.
- Runtime Hooks: Run as an action during the flow — added directly into flow instructions, allows real-time backend interaction during testing
- Teardown Hooks: Run at the very end of suites and flows. Helpful to clean up testing states
Hook Types
Hooks allow you to configure your test environment in three ways:- Scripts: Python, JavaScript, TypeScript, or Bash scripts that run server-side
- cURL Requests: Backend API calls for simple HTTP requests
- App Launch Configuration: Configure how your mobile app launches (feature flags, environment settings) - mobile only
Scripts
Server-side scripts that execute in a secure sandbox environment. Choose from Python, JavaScript, TypeScript, or Bash depending on your needs.If your hook calls a firewalled API, see Network allowlist for the IPs to allow.
- Complex multi-step API operations
- Data processing and transformation
- Conditional logic based on API responses
- Generating dynamic test data
- Chaining multiple API calls with error handling
Generating Random Values
Use cryptographically secure randomness from the language standard library when generating unique test data. JavaScript / TypeScript:random module, seed it from OS entropy at the top of your script:
cURL Requests
Backend API calls that execute before (setup) or after (teardown) a flow runs. Best for simple, single HTTP requests. Common use cases:- Create test user accounts via your API
- Reset database state between flows
- Generate auth tokens or session data
- Configure backend feature flags
- Clean up test data after flows complete
App Launch Configuration (Mobile Only)
Configure values that are passed to your mobile app when it launches. These values are available to your app code as environment variables (iOS) or intent extras (Android).App Launch Configuration is only available for mobile apps (iOS and Android). For web testing, use Scripts or cURL Requests to configure your test environment.
- Override feature flag values for specific test scenarios
- Set test environment parameters (staging vs. production mode)
- Configure API timeouts or retry behavior
- Enable debug modes or verbose logging
- Set experiment variants for A/B testing
Creating a Hook
- Navigate to Hooks in the sidebar
- Click Create Hook
- Enter a hook name (e.g., “Create Test User” or “Generate Auth Token”)
- Select hook type:
- Python: For complex logic and data processing
- JavaScript: For Node.js-based operations
- TypeScript: For type-safe Node.js operations
- Bash: For shell script operations
- cURL Request: For simple HTTP API calls
- App Launch Configuration: For mobile app settings (mobile only)
- Enter your script or configuration:
For Python:
For JavaScript:
For TypeScript:
For Bash:
For cURL Requests:
For App Launch Configuration:
- Click Create Hook
Testing Hooks
Before attaching hooks to flows, you can test them to verify they work correctly.- Open the hook you want to test
- Click the Test Hook button
- The hook will execute with a 1-minute timeout
- View the output to verify success or debug issues
- Script executes without errors
- API calls return expected responses
- Environment variables are being read correctly
- Exported values (if any) are formatted correctly
Using Hooks
Setup & Teardown Hooks
Attaching Setup & Teardown Hooks- Create a new suite or flow or click Edit on an existing one
- Expand the Advanced section
- Expand the Setup Hooks or Teardown Hooks section
- Click the Add a setup hook… or Add a teardown hook… button
- Select the hook you want to attach
Runtime Hooks
You can execute hooks as actions during flow execution by using the syntax${hooks:Hook Name} in the flow instructions.
Example:
${hooks:Hook Name}, it will:
- Look up the hook by name
- Execute the hook script
- Continue with the rest of the action
- Creating data mid-flow (e.g., “add 5 items to cart, then
${hooks:Create Dummy Discount Code}”) - Triggering backend events at specific points
- Resetting state between actions
Execution Order
- Setup Hook executes (if configured)
- Flow runs on app start
- Agent runs actions and any Runtime Hooks (if configured)
- Flow run stops
- Teardown Hook executes (if configured)
Environment Variables in Hooks
For cURL Requests
Reference environment variables using${env:VARIABLE_NAME} syntax:
API_URL=https://staging-api.example.comTEST_EMAIL=test@staging.comTEST_PASSWORD=SecurePass123
For Scripts (Python, JavaScript, TypeScript, Bash)
Environment variables are automatically injected into the script environment. Access them using your language’s standard method: Python:Sharing Data Between Hooks
Hooks can pass data to subsequent hooks in the same suite. This is useful for scenarios like:- Generating an auth token in a setup hook and using it in a runtime hook
- Creating a test user and passing the user ID to a teardown hook for cleanup
- Sharing credentials across multiple flows in a suite
How It Works
- In your hook, write values to
/tmp/autosana.envinKEY=VALUEformat - Subsequent hooks can access these values as environment variables
- Values persist for all subsequent hooks in the suite (across all flows)
Key Naming Rules
When exporting values, keys must follow these rules:Example: Passing a Token Between Hooks
Setup Hook (Python) - Creates token:Important Notes
- Scripts can read and write exported values
- cURL hooks can only read exported values (they cannot write to
/tmp/autosana.env) - If multiple hooks export the same key, the latest value wins
- Exported values are available to all subsequent hooks in the suite (across all flows)
- Exported values are also available to subsequent flows in the suite via
${env:KEY} - The agent can also retrieve exported values directly by name using Get Variable
Hook Examples
cURL Examples
Create User Account
Reset Database
Generate Auth Token
Delete Test Data (Teardown)
Script Examples
Python: Create User and Export Credentials
JavaScript: Fetch and Process Data
Bash: Quick API Check
App Launch Configuration (Mobile Only)
How It Works
App Launch Configuration hooks pass values to your mobile app when it launches. These values are set at app startup and are available throughout your test. This feature is only available for iOS and Android apps. Important: Launch configuration is applied when the app starts. Within a suite, the launch configuration from the first flow will be used for all flows in that suite.Dynamic Values (Environment & Build Variables)
Launch configuration JSON supports${env:VARIABLE_NAME} placeholders, resolved when the app launches. Values come from your environment variables and from build variables passed via CI (the variables input on the GitHub Action / upload API). This lets you drive launch configuration dynamically — for example, passing an Expo Updates channel from CI:
Updates.setUpdateURLAndRequestHeadersOverride(...) followed by Updates.reloadAsync() to switch channels at runtime.
If a referenced variable has no value, the hook fails with a clear error rather than launching your app with a literal ${env:...} string.
Accessing Values in Your App
iOS (Swift):On iOS, launch configuration values are set as environment variables and accessed via
ProcessInfo.processInfo.environment. On Android, they are passed as intent extras and accessed via intent.extras. See the platform-specific examples above for details.Launch Configuration Examples
Override Feature Flags
Set Environment and Timeouts
A/B Testing Configuration
Debug Mode Settings
When to Use Each Hook Type
Setup Hooks & Agent Context
Pro Tip: When a hook produces output (via print statements, console.log, or echo), the agent automatically receives this data as additional context and can use it during flow execution. Example setup hook:Timeouts
Hooks have different timeout limits depending on the context:
If a hook exceeds its timeout, it will be terminated and marked as failed.
Best Practices
Hooks vs Suite Auth Instructions
Use hooks when: You need to configure backend state, create test data, or call APIs
Use suite auth instructions when: You need to start the suite from a specific state (e.g., logged in with a certain test account)
Troubleshooting
Script Issues
Script times out- Hooks have a 5-minute timeout during flow execution (1 minute when testing)
- Break long operations into multiple hooks
- Check for infinite loops or slow API endpoints
- Verify the variable exists in Settings → Environments
- Check spelling and case (variable names are case-sensitive)
- For scripts, use the correct access method for your language
- Hook sandboxes are created from snapshots, so pseudo-random generators may repeat their seed across runs
- In JavaScript/TypeScript, use Node’s built-in
cryptomodule (crypto.randomInt,crypto.randomUUID) instead ofMath.random() - In Python, prefer
secretsoruuid; if you must userandom, callrandom.seed(os.urandom(32))before generating values
- Verify you wrote to
/tmp/autosana.env(exact path) - Check key naming rules (alphanumeric + underscore, can’t start with number)
- Ensure the format is
KEY=VALUEwith one per line
cURL Request Issues
Hook fails to execute- Verify the curl command works in your terminal first
- Check that environment variables are defined
- Ensure API endpoints are accessible from Autosana’s infrastructure
- Syntax must be
${env:VARIABLE_NAME}(not{{VARIABLE_NAME}}or$VARIABLE_NAME) - Variable names are case-sensitive
- Variables must exist in Settings → Environments
App Launch Configuration Issues
Configuration not appearing in app- Verify JSON is valid (use a JSON validator)
- Check you’re accessing values correctly for your platform (ProcessInfo for iOS, intent.extras for Android)
- Ensure the hook is attached as a setup hook (launch configuration doesn’t work in teardown)
- On iOS, all values become strings (including numbers and booleans)
- On Android, primitives keep their types (int, float, boolean, string)
- Nested objects are JSON-serialized as strings on both platforms
- Use the examples in this guide to parse nested structures correctly
Data Sharing Issues
Hook can’t read value from previous hook- Ensure the previous hook successfully wrote to
/tmp/autosana.env - Check that the previous hook completed without errors
- Verify the key name matches exactly (case-sensitive)
- Keys must contain only letters, numbers, and underscores
- Keys cannot start with a number
- Examples:
AUTH_TOKEN✓,123_KEY✗,API-KEY✗