This add-on supports the Automation Framework.
The script job allows you to execute various actions with scripts:
Adds the specified script to ZAP. Scripts are enabled but not configured to be loaded when ZAP restarts.
By default the default script engine for the file extension (if any) will be used - this may be overridden using the ’engine’ parameter.
The source parameter was previously called file, both will work.
Removes the specified script from ZAP.
Runs the specified script in ZAP. The script must already be available in ZAP, for example added using the ‘add’ action.
If user is specified, the user is set on the Zest script.
Authentication happens when the browser is actually launched during script execution (for example, when a ZestClientLaunch runs), not before scripts start.
For chains, the execution path is the same for single-script and multi-script chains. Authentication might not occur if no browser launch is executed in that run.
The run action can execute one or more Zest standalone scripts in sequence using the chain parameter.
This is useful for workflows that require several scripts to run in order.
Chaining requires the Zest add-on to be installed. If it is not loaded or chain preparation fails, the job reports an error and the chain does not run.
chain and name are specified, chain is used and name is ignored (a warning is issued)ZestClientLaunch)If chain preparation fails (e.g. Zest not loaded), the job reports an error and the chain does not run. If any script in the chain fails during execution, the job reports an error and stops; later scripts in the chain are not run. In this case, browser windows opened by the chain might not be closed immediately and are closed when ZAP shuts down.
- type: script
parameters:
action: run
type: standalone
chain:
- access-script
- navigate-script
- perform-action-script
context: mycontext
user: testuser
Loads all of the scripts in the subdirectories under the specified source path to ZAP. Scripts are enabled but not configured to be loaded when ZAP restarts.
The scripts must be in subdirectories named after the relevant script type (such as ‘active’, ‘passive’, ‘proxy’ etc) and must have an appropriate extension for the script language used.
Enables the specified script. The script must already be available in ZAP, for example added using the ‘add’ action.
Disables the specified script. The script must already be available in ZAP, for example added using the ‘add’ action.
Not all of the parameters are valid for all of the actions, see above for details.
- type: script
parameters:
action: # String: The executed action - available actions: add, remove, run, enable, disable
type: # String: The type of the script
engine: # String: The script engine to use - can be used to override the default engine for the file extension
name: # String: The name of the script, defaults to the file name (for single script run; ignored if 'chain' is specified)
chain: # List: optional; script names to run in sequence (takes precedence over name if both specified)
source: # String: The full or relative file path, must be readable
inline: # String: The full script (may be multi-line) - supply this or 'source' not both
target: # String: The URL to be invoked for "targeted" script type
context: # String: The name of the context to use when running the script (optional)
user: # String: The name of the user to use when running the Zest standalone script or chain (optional, requires context)
The source parameter was previously called file, both will work.
Inline scripts are where the script contents are in the YAML plan rather that a separate file. An example of adding and running a simple standalone inline script is:
- type: script
parameters:
action: "add"
type: "standalone"
engine: "ECMAScript : Graal.js"
name: "inline-test"
inline: |
print("This is a simple example")
print("Of a multi-line script")
- type: script
parameters:
action: "run"
type: "standalone"
name: "inline-test"
Scripts can interact with running plans using code like:
var extAF = control.getExtensionLoader().getExtension("ExtensionAutomation");
var plans = extAF.getRunningPlans();
if (plans.size() > 0) {
plans.get(0).getProgress().info("An info message added by a script");
} else {
print('No running plans');
}