How to Create Lifecycle Hooks
Background
Lifecycle HooksWriting a Lifecycle Hooks Script
We currently only support lifecycle hook scripts written in Python.
Write a Python script (e.g. lifecycle_hooks.py)
In this script, define the lifecycle events to hook into
Define what kind of behavior to execute for each of those events
Below is an example of a simple script that prints some strings during two events. In the script there are two functions with names that correspond to its lifecycle event:
handle_before_replay
is for before a Request or Scenario gets replayedhandle_after_replay
is for after a Request or Scenario gets replayed
Before a request or scenario gets replayed, the string "Before replay!" will be printed and after the replay, "After replay!" will be printed.
Each function takes a single context object. Manipulating this object will affect the behaviour of the request interception.
Enabling Lifecycle Hook Scripts Use
Once your script is written, it can now be used by the Agent.
Lifecycle hooks are currently supported for these commands:
stoobly-agent run
stoobly-agent request replay
stoobly-agent scenario replay
stoobly-agent endpoint import
For all of the above commands, the flag to specify the path to the lifecycle hooks file is --lifecycle-hooks-path <PATH>
For example, if you want to replay a request the command would look something like this:
Last updated