Skip to content

Setup

This module contains step implementations that setup the load test scenario with parameters that is going to be used in the scenario they are defined in.

Given set context variable

Given set context variable "{variable}" to "{value}"

[view_source]

Set a variable in the scenario and user context.

If this step is before any step that adds a task in the scenario, it will be added to the context which the user is initialized with at start. If it is after any tasks, it will be added as a task which will change the context variable value during runtime.

Variable names can contain (one or more) dot (.) or slash (/) to indicate that the variable has a nested structure. E.g. token.url and token/url results in {'token': {'url': '<value'>}}

It is also possible to have spaces in a variable names, they will then be replaced with underscore (_), and the name will be converted to lowercase.

E.g. Client ID results in client_id.

Example:

And set context variable "token.url" to "https://example.com/api/auth"
And set context variable "token/client_id" to "aaaa-bbbb-cccc-dddd"
And set context variable "token/client secret" to "aasdfasdfasdf=="
And set context variable "token.resource" to "0000-aaaaaaa-1111-1111-1111"
And set context variable "log_all_requests" to "True"
And set context variable "validate_certificates" to "False"

Arguments:

  • variable str - name, can contain . and /
  • value str - value, data type will be guessed and casted

Given iterations

Given repeat for "{value}" {iteration_number:IterationGramaticalNumber}

[view_source]

Set how many iterations of the Tasks in the scenario should execute.

Default value is 1. A value of 0 means to run until all test data is consumed, or that the (optional) specified runtime for the scenario is reached.

Example:

And repeat for "10" iterations
And repeat for "1" iteration
And value for variable "leveranser" is "100"
And repeat for "{{ leveranser * 0.25 }}" iterations

Arguments:

  • value str - number of iterations of the scenario, can be a templatning string or a environment configuration variable

Given pace

Given set iteration time to "{pace_time}" milliseconds

[view_source]

Set minimum time one iterations of the Tasks in the scenario should take. E.g. if pace is set to 2000 ms and the time since it last ran was 300 ms, this task will sleep for 1700 ms. If the time of all tasks is greater than the specified time, there will be an error, but the scenario will continue.

This is useful to be able to control the intensity towards the loadtesting target.

Example:

Then set iteration time to "2000" milliseconds
Then set iteration time to "{{ pace }}" milliseconds

Given set variable alias

Given set alias "{alias}" for variable "{variable}"

[view_source]

Create an alias for a variable that points to another structure in the context.

This is useful if you have test data that somehow should change the behavior for a user, e.g. username and password.

Example:

And value for variable "AtomicCsvReader.users" is "users.csv | repeat=True"
And set alias "auth.user.username" for variable "AtomicCsvReader.users.username"
And set alias "auth.user.password" for variable "AtomicCsvReader.users.password"

Variables in payload templates are not allowed to have an alias.

Arguments:

  • alias str - which node in the context that should get the value of variable
  • variable str - an already initialized variable that should be renamed

Given log all requests

Given log all requests

[view_source]

Set if all requests should be logged to a file.

By default only failed requests (and responses) will be logged.

Example:

And log all requests

Given stop user on failure

Given stop user on failure

[view_source]

Stop user if a request fails.

Default behavior is to continue the scenario if a request fails.

Example:

And stop user on failure

Given restart scenario on failure

Given restart scenario on failure

[view_source]

Restart scenario, from first task, if a request fails.

Default behavior is to continue the scenario if a request fails.

Example:

And restart scenario on failure

Then metadata

Then metadata "{key}" is "{value}"

[view_source]

Set a metadata (header) value to be used by the user when sending requests.

When step expression is used before any tasks has been added in the scenario the metadata will be used for all requests the specified loadtesting user executes in the scenario.

If used after a Request task, the metadata will be added and only used for that request.

If used after a task that implements grizzly.auth.GrizzlyHttpAuthClient (e.g. HTTP), the metadata will be added and only used when that task executes.

Example:

And metadata "Content-Type" is "application/xml"
And metadata "Ocp-Apim-Subscription-Key" is "9asdf00asdf00adsf034"

Or, for use in one request only, specify metadata after the request:

Then post request ...
And metadata "x-header" is "{{ value }}"

Then get "https://{{ client_url }}" with name "client-http" and save response payload in "payload"
And metadata "Ocp-Apim-Subscription-Key" is "deadbeefb00f"