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
| Name | Type | Description |
|---|---|---|
method | string | The HTTP method (e.g., "GET", "POST", "PUT", "DELETE"). |
- Source
Given I set a k6 script for GET testing
Given I set a k6 script for POST testingThen_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"
| Name | Type | Description |
|---|---|---|
jsonPath | string | A dot-separated JSON path to the value in the last response (e.g., "data.user.id"). |
alias | string | The name of the alias to store the value under (e.g., "userId"). |
- Source
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"
| Name | Type | Description |
|---|---|---|
endpoint | string | The API endpoint for the login request (relative to |
fileName | string | The name of the JSON file containing login credentials. |
- Source
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"
| Name | Type | Description |
|---|---|---|
authType | string | The type of authentication (e.g., "BearerToken", "BasicAuth", "APIKey"). |
- Source
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
| Name | Type | Description |
|---|---|---|
docString | string | A DocString containing a newline-separated list of endpoints. |
- Source
When I set the following endpoints used:
/health
/status
/metricsWhen_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 |
| Name | Type | Description |
|---|---|---|
dataTable | DataTable | A Cucumber data table containing k6 configuration parameters. Expected columns: |
- Source
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" }
| Name | Type | Description |
|---|---|---|
method | string | The HTTP method (e.g., "POST", "PUT"). |
endpoint | string | The specific endpoint URL for this body. |
docString | string | A DocString containing the request body content (e.g., JSON). |
- Source
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> |
| Name | Type | Description |
|---|---|---|
dataTable | DataTable | A Cucumber data table with 'Header' and 'Value' columns. |
- Source
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"
| Name | Type | Description |
|---|---|---|
fileName | string | The name of the JSON payload file (e.g., "user_data.json"). |
method | string | The HTTP method (only "POST", "PUT", "PATCH" are supported for bodies). |
endpoint | string | The specific endpoint URL. |
- Source
When I use JSON payload from "login_payload.json" for POST to "/auth/login"Type Definitions
CustomWorld
- Object
| Name | Type | Description |
|---|---|---|
config | Object | |
aliases | Object | |
lastResponse | Object | |
parameters | Object | |
log | function |
- Source
K6Config
- Object
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
method | string | HTTP method for the request (e.g., "GET", "POST"). | |||||||||||||||||||||||||||||||||||||
endpoint | string | <optional> | The specific endpoint for a single request. | ||||||||||||||||||||||||||||||||||||
endpoints | Array.<string> | <optional> | An array of endpoints for multiple requests. | ||||||||||||||||||||||||||||||||||||
headers | Object | <optional> | Request headers. | ||||||||||||||||||||||||||||||||||||
body | string | <optional> | Request body content. | ||||||||||||||||||||||||||||||||||||
options | Object | k6 test options (vus, duration, stages, thresholds). Properties
|
- Source