Methods

Given_I_set_k6_script_for_method_testing(method)

Initializes the k6 script configuration by setting the primary HTTP method for the load test.

Given I set a k6 script for {word} testing
Parameters:
NameTypeDescription
methodstring

The HTTP method (e.g., "GET", "POST", "PUT", "DELETE").

Example
Given I set a k6 script for GET testing
Given I set a k6 script for POST testing

Then_I_store_value_as_alias(jsonPath, alias)

Stores a value from the last API response into the Cucumber World's aliases context.

Then I store the value at "data.token" as alias "authToken"
Parameters:
NameTypeDescription
jsonPathstring

A dot-separated JSON path to the value in the last response (e.g., "data.user.id").

aliasstring

The name of the alias to store the value under (e.g., "userId").

Example
Then I store the value at "token" as alias "accessToken"
Then I store the value at "user.profile.email" as alias "userEmail"

When_I_login_via_POST_with_payload_from_file(endpoint, fileName)

Logs in via a POST request to a specified endpoint using a JSON payload from a file. The response data is stored for subsequent steps.

When I login via POST to "/auth/login" with payload from "admin_credentials.json"
Parameters:
NameTypeDescription
endpointstring

The API endpoint for the login request (relative to BASE_URL).

fileNamestring

The name of the JSON file containing login credentials.

Example
When I login via POST to "/api/login" with payload from "user_creds.json"

When_I_set_authentication_type(authType)

Sets the authentication type for the k6 request, generating relevant headers.

When I set the authentication type to "BearerToken"
Parameters:
NameTypeDescription
authTypestring

The type of authentication (e.g., "BearerToken", "BasicAuth", "APIKey").

Example
When I set the authentication type to "BearerToken"

When_I_set_endpoints_used(docString)

Sets the list of endpoints to be used in the k6 script. These are typically used when the k6 script iterates over multiple URLs.

When I set the following endpoints used:
/api/v1/users
/api/v1/products
/api/v1/orders
Parameters:
NameTypeDescription
docStringstring

A DocString containing a newline-separated list of endpoints.

Example
When I set the following endpoints used:
/health
/status
/metrics

When_I_set_k6_script_configurations(dataTable)

Configures the k6 script options (VUs, duration, stages, thresholds) from a data table.

When I set to run the k6 script with the following configurations:
| virtual_users | duration | stages               | http_req_failed | http_req_duration | error_rate      |
| 10            | 30       |                      | p(99)<0.01      | p(99)<500         | rate<0.01       |
|               |          | [{"duration":"10s","target":10}] | p(90)<0.01      | p(90)<200         | rate<0.001      |
Parameters:
NameTypeDescription
dataTableDataTable

A Cucumber data table containing k6 configuration parameters. Expected columns: virtual_users, duration, stages (JSON string), http_req_failed, http_req_duration, error_rate.

Example
When I set to run the k6 script with the following configurations:
| virtual_users | duration | http_req_failed | http_req_duration |
| 50            | 60       | p(99)<0.01      | p(99)<1000        |
When I set to run the k6 script with the following configurations:
| stages                                  | http_req_failed | http_req_duration | error_rate |
| [{"duration":"10s","target":10}, {"duration":"20s","target":50}] | p(99)<0.01      | p(99)<500         | rate<0.01  |

When_I_set_method_body_for_endpoint(method, endpoint, docString)

Sets the request body for a specific HTTP method and endpoint.

When I set the following POST body is used for "/api/v1/create"
{ "name": "test", "email": "test@example.com" }
Parameters:
NameTypeDescription
methodstring

The HTTP method (e.g., "POST", "PUT").

endpointstring

The specific endpoint URL for this body.

docStringstring

A DocString containing the request body content (e.g., JSON).

Example
When I set the following PUT body is used for "/api/v1/update/1"
{ "status": "active" }

When_I_set_request_headers(dataTable)

Sets request headers for the k6 script. Headers are merged with any existing headers.

When I set the request headers:
| Header         | Value                |
| Content-Type   | application/json     |
| Authorization  | Bearer <my_token>    |
Parameters:
NameTypeDescription
dataTableDataTable

A Cucumber data table with 'Header' and 'Value' columns.

Example
When I set the request headers:
| Header         | Value               |
| Content-Type   | application/json    |
| X-Custom-Header| MyValue             |

When_I_use_JSON_payload_from_file_for_method_to_endpoint(fileName, method, endpoint)

Loads a JSON payload from a file to be used as the request body for a specific method and endpoint in the k6 script.

When I use JSON payload from "user_create.json" for POST to "/api/v1/users"
Parameters:
NameTypeDescription
fileNamestring

The name of the JSON payload file (e.g., "user_data.json").

methodstring

The HTTP method (only "POST", "PUT", "PATCH" are supported for bodies).

endpointstring

The specific endpoint URL.

Example
When I use JSON payload from "login_payload.json" for POST to "/auth/login"

Type Definitions

CustomWorld

Type:
  • Object
Properties
NameTypeDescription
configObject
aliasesObject
lastResponseObject
parametersObject
logfunction

K6Config

Type:
  • Object
Properties
NameTypeAttributesDescription
methodstring

HTTP method for the request (e.g., "GET", "POST").

endpointstring<optional>

The specific endpoint for a single request.

endpointsArray.<string><optional>

An array of endpoints for multiple requests.

headersObject<optional>

Request headers.

bodystring<optional>

Request body content.

optionsObject

k6 test options (vus, duration, stages, thresholds).

Properties
NameTypeAttributesDescription
thresholdsObject

k6 metric thresholds.

Properties
NameTypeAttributesDescription
http_req_failedArray.<string>

Thresholds for failed HTTP requests.

http_req_durationArray.<string>

Thresholds for request duration.

error_rateArray.<string><optional>

Optional threshold for error rate.

vusnumber<optional>

Number of virtual users (for open model).

durationstring<optional>

Test duration (for open model, e.g., "30s").

stagesArray.<Object><optional>

Array of stages for a stepped load model.