Intro to Scripts
What can be achieved with scripts:
- Test (assert) the correctness of the results returned by the request (postprocessor script).
- Modify API request parameters dynamically, such as adding API signature parameters, etc (preprocessor script).
- Pass data between API requests (using scripts to manipulate variables).
- Directly call programs written in other languages. We support java(.jar), python, PHP, JS, BeanShell, go, shell, Ruby, Lua, etc.
Apidog script syntax is 100% compatible with Postman script syntax. Postman scripts can be seamlessly migrated to Apidog.
Scripts can be added in the following two stages:
- Use preprocessor scripts before sending the request to the server.
- Use the postprocessor script (assertion) after receiving the response.
Global scripts and group scripts:
- Support preprocessor and postprocessor in global settings (set in the project overview). These will take effect at runtime.
- Support preprocessor and postprocessor in group settings (set in the project overview). These will take effect at runtime.
The execution order of the API request is as follows:
Global preprocessor scripts -> Group preprocessor script -> API preprocessor script -> Send API request -> Return Response -> Global postprocessor script -> Group postprocessor Script -> API postprocessor script
You can write debugging scripts in preprocessor and postprocessor, and you can log output information through console.log("message"). Open the control panel to view it.