k6-cucumber-steps 1.0.16 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  {
2
- "recommendations": [
3
- "cucumberopen.cucumber-official"
4
- ]
5
- }
2
+ "recommendations": [
3
+ "cucumberopen.cucumber-official",
4
+ "alexkrechik.cucumberautocomplete"
5
+ ]
6
+ }
@@ -5,6 +5,8 @@
5
5
  "src/features/**/*.k6.feature",
6
6
  "src/features/template/*.feature"
7
7
  ],
8
- "cucumber.glue": ["step_definitions/*.js","src/features/stepDefinitions/*.js"
9
- ]
8
+ "cucumber.glue": [
9
+ "step_definitions/*.js",
10
+ "src/features/stepDefinitions/*.js"
11
+ ]
10
12
  }
package/README.md CHANGED
@@ -33,39 +33,122 @@ Run [k6](https://k6.io/) performance/load tests using [Cucumber](https://cucumbe
33
33
  npm install k6-cucumber-steps
34
34
  ```
35
35
 
36
- ---
37
-
38
36
  ## 🚀 Usage
39
37
 
40
38
  ### CLI
41
39
 
42
40
  ```bash
43
- npx k6-cucumber-steps run --feature ./features/example.feature
41
+ npx k6-cucumber-steps run [options]
42
+ ```
43
+
44
+ #### Options
45
+
46
+ The `run` command accepts the following options:
47
+
48
+ - `-f, --feature <path>`: Path to the feature file to execute.
49
+ - `-t, --tags <string>`: Cucumber tags to filter scenarios (e.g., `@smoke and not @regression`).
50
+ - `-r, --reporter`: Generate HTML and JSON reports in the `reports` directory. This is a boolean flag, so just include `-r` or `--reporter` to enable it.
51
+
52
+ ### Example Usage with Options
53
+
54
+ ```bash
55
+ npx k6-cucumber-steps run --feature ./features/my_feature.feature --tags "@load and not @wip" --reporter
44
56
  ```
45
57
 
46
- ### Programmatic
58
+ ---
59
+
60
+ ## 🛠️ Getting Started
61
+
62
+ Here's a step-by-step guide to using `k6-cucumber-steps` in your project:
63
+
64
+ **Prerequisites:**
65
+
66
+ 1. **Node.js and npm (or yarn):** Ensure you have Node.js and npm (or yarn) installed.
67
+ 2. **k6:** Install k6 on your system following the instructions at [k6.io/docs/getting-started/installation/](https://www.google.com/search?q=https://k6.io/docs/getting-started/installation/).
68
+ 3. **@cucumber/cucumber:** This package is required for using Cucumber.
69
+ 4. **cucumber-html-reporter:** This package is needed if you intend to generate detailed HTML reports
70
+
71
+ **Setup:**
72
+
73
+ 1. **Create a new project:**
47
74
 
48
- ```ts
49
- import { runK6Feature } from "k6-cucumber-steps";
75
+ ```bash
76
+ mkdir my-performance-test
77
+ cd my-performance-test
78
+ npm init -y
79
+ # or
80
+ yarn init -y
81
+ ```
50
82
 
51
- await runK6Feature("./features/example.feature");
83
+ 2. **Install dependencies:**
84
+
85
+ ```bash
86
+ npm install --save-dev @cucumber/cucumber k6 dotenv k6-cucumber-steps cucumber-html-reporter
87
+ # or
88
+ yarn add --dev @cucumber/cucumber k6 dotenv k6-cucumber-steps cucumber-html-reporter
89
+ ```
90
+
91
+ 3. **Create `.env` file (optional):** Create a `.env` file in your project root for environment variables as described in the "Environment Variables" section below.
92
+
93
+ 4. **Create `features` directory and feature files:**
94
+
95
+ ```bash
96
+ mkdir features
97
+ # Create your .feature files inside the features directory (e.g., example.feature)
98
+ ```
99
+
100
+ 5. **Configure `cucumber.js`:**
101
+ Create a `cucumber.js` file at the root of your project with the following content:
102
+
103
+ ```javascript
104
+ // cucumber.js
105
+ require("dotenv").config();
106
+
107
+ module.exports = {
108
+ requireModule: ["@babel/register"], // If your features or local steps need transpilation
109
+ require: [
110
+ "./node_modules/k6-cucumber-steps/step_definitions/**/*.js", // Path to k6-cucumber-steps' step definitions
111
+ // You can add paths to your local step definitions here if needed
112
+ ],
113
+ format: [
114
+ "summary",
115
+ "json:reports/load-report.json", // For JSON report
116
+ "html:reports/report.html", // For HTML report (requires @cucumber/html-formatter)
117
+ ],
118
+ tags: process.env.TAGS,
119
+ };
120
+ ```
121
+
122
+ **Running Tests:**
123
+
124
+ From the root of your project, use the CLI command:
125
+
126
+ ```bash
127
+ npx k6-cucumber-steps run
128
+ ```
129
+
130
+ You can also specify a feature file or tags:
131
+
132
+ ```bash
133
+ npx k6-cucumber-steps run --feature features/example.feature -t "@yourTag"
52
134
  ```
53
135
 
54
136
  ---
55
137
 
56
- ## Setup
138
+ ## Setup (Detailed)
57
139
 
58
- 1. **Environment Variables**: Create a `.env` file in your project root based on the provided `.env.example`:
140
+ 1. **Environment Variables**: Create a `.env` file in your project root based on the provided `.env.example`:
59
141
 
60
- ```env
61
- BASE_URL=https://api.example.com
62
- API_KEY=your_api_key
63
- BEARER_TOKEN=your_bearer_token
64
- BASIC_USER=your_basic_user
65
- BASIC_PASS=your_basic_pass
66
- ```
142
+ ```env
143
+ BASE_URL=[https://api.example.com](https://api.example.com)
144
+ API_KEY=your_api_key
145
+ BEARER_TOKEN=your_bearer_token
146
+ BASIC_USER=your_basic_user
147
+ BASIC_PASS=your_basic_pass
148
+ TAGS=@yourTag
149
+ ```
67
150
 
68
- 2. **Feature Files**: Write your feature files using the provided step definitions.
151
+ 2. **Feature Files**: Write your feature files using the provided step definitions.
69
152
 
70
153
  ## Gherkin Examples
71
154
 
@@ -77,17 +160,17 @@ Here’s how you can write a feature file using the provided step definitions:
77
160
  Feature: API Performance Testing
78
161
 
79
162
  Scenario: Run load tests with dynamic GET requests
80
- Given I have a k6 script for GET testing
81
- When I run the k6 script with the following configurations:
163
+ Given I set a k6 script for GET testing
164
+ When I set to run the k6 script with the following configurations:
82
165
  | virtual_users | duration | http_req_failed | http_req_duration |
83
166
  | 50 | 10 | rate<0.05 | p(95)<3000 |
84
- And the following endpoint(s) is/are used:
167
+ And I set the following endpoint(s) used:
85
168
  """
86
169
  /api/profile
87
- https://reqres.in/api/users?page=2
170
+ [https://reqres.in/api/users?page=2](https://reqres.in/api/users?page=2)
88
171
  """
89
172
  And when the authentication type is "none"
90
- Then the API should handle the GET request successfully
173
+ Then I see the API should handle the GET request successfully
91
174
  ```
92
175
 
93
176
  ### Example 2: Test POST Endpoint with Bearer Token Authentication
@@ -96,23 +179,23 @@ Feature: API Performance Testing
96
179
  Feature: API Performance Testing
97
180
 
98
181
  Scenario: Run load tests with dynamic POST requests
99
- Given I have a k6 script for POST testing
100
- When I run the k6 script with the following configurations:
182
+ Given I set a k6 script for POST testing
183
+ When I set to run the k6 script with the following configurations:
101
184
  | virtual_users | duration | http_req_failed | http_req_duration |
102
185
  | 20 | 60 | rate<0.01 | p(95)<300 |
103
186
  And the authentication type is "bearer_token"
104
- And the following endpoint(s) is/are used:
187
+ And I set the following endpoint(s) used:
105
188
  """
106
189
  /api/v1/users
107
190
  """
108
- And the following POST body is used for "/api/v1/users"
191
+ And I set the following POST body is used for "/api/v1/users"
109
192
  """
110
193
  {
111
194
  "username": "{{username}}",
112
195
  "email": "{{faker.internet.email}}"
113
196
  }
114
197
  """
115
- Then the API should handle the POST request successfully
198
+ Then I see the API should handle the POST request successfully
116
199
  ```
117
200
 
118
201
  ## Step Definitions
@@ -120,33 +203,33 @@ Feature: API Performance Testing
120
203
  ### Authentication Steps
121
204
 
122
205
  ```gherkin
123
- When the authentication type is "api_key"
124
- When the authentication type is "bearer_token"
125
- When the authentication type is "basic"
126
- When the authentication type is "none"
206
+ When I set the authentication type is "api_key"
207
+ When I set the authentication type is "bearer_token"
208
+ When I set the authentication type is "basic"
209
+ When I set the authentication type is "none"
127
210
  ```
128
211
 
129
212
  ### Request Configuration Steps
130
213
 
131
214
  ```gherkin
132
- Given I have a k6 script for {word} testing
133
- When I run the k6 script with the following configurations:
134
- When the request headers are:
135
- When the following endpoint(s) is/are used:
136
- When the following {word} body is used for {string}
215
+ Given I set a k6 script for {word} testing
216
+ When I set to run the k6 script with the following configurations:
217
+ When I set the request headers:
218
+ When I set the following endpoint(s) used:
219
+ When I set the following {word} body is used for {string}
137
220
  ```
138
221
 
139
222
  ### Assertion Steps
140
223
 
141
224
  ```gherkin
142
- Then the API should handle the {word} request successfully
225
+ Then I see the API should handle the {word} request successfully
143
226
  ```
144
227
 
145
228
  ## Test Results
146
229
 
147
230
  Below is an example of the Cucumber report generated after running the tests:
148
-
149
- ![Cucumber Report](./assets/k6-cucumber-report.png)
231
+ <img src="assets/k6-cucumber-report.png" alt="Cucumber report generated after running the tests" width="60%" />
232
+ <img src="assets/k6-cucumber-report2.png" alt="Cucumber report generated after running the tests" width="60%" />
150
233
 
151
234
  ### Explanation of the Report
152
235
 
Binary file
package/index.js CHANGED
@@ -1,6 +1 @@
1
- // Export all exports from your helper files
2
- export * from "./lib/helpers/buildK6Script";
3
- export * from "./lib/helpers/generateHeaders";
4
- export * from "./lib/helpers/resolveBody";
5
- export * from "./lib/utils/k6Runner";
6
1
  export * from "./step_definitions/load_test_steps.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k6-cucumber-steps",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,35 +36,35 @@ export function Then(
36
36
  ): void;
37
37
 
38
38
  declare function Given(
39
- pattern: "I have a k6 script for {word} testing",
39
+ pattern: "I set a k6 script for {word} testing",
40
40
  implementation: (
41
41
  this: import("@cucumber/cucumber").World,
42
42
  method: string
43
43
  ) => void
44
44
  ): void;
45
45
  declare function When(
46
- pattern: "I run the k6 script with the following configurations:",
46
+ pattern: "I set to run the k6 script with the following configurations:",
47
47
  implementation: (
48
48
  this: import("@cucumber/cucumber").World,
49
49
  dataTable: DataTable
50
50
  ) => void
51
51
  ): void;
52
52
  declare function When(
53
- pattern: "the request headers are:",
53
+ pattern: "I set the request headers:",
54
54
  implementation: (
55
55
  this: import("@cucumber/cucumber").World,
56
56
  dataTable: DataTable
57
57
  ) => void
58
58
  ): void;
59
59
  declare function When(
60
- pattern: "the following endpoint\\(s) is\\/are used:",
60
+ pattern: "I set the following endpoint\\(s) used:",
61
61
  implementation: (
62
62
  this: import("@cucumber/cucumber").World,
63
63
  docString: string
64
64
  ) => void
65
65
  ): void;
66
66
  declare function When(
67
- pattern: "the following {word} body is used for {string}",
67
+ pattern: "I set the following {word} body is used for {string}",
68
68
  implementation: (
69
69
  this: import("@cucumber/cucumber").World,
70
70
  method: string,
@@ -73,14 +73,14 @@ declare function When(
73
73
  ) => void
74
74
  ): void;
75
75
  declare function When(
76
- pattern: "the authentication type is {string}",
76
+ pattern: "I set the authentication type is {string}",
77
77
  implementation: (
78
78
  this: import("@cucumber/cucumber").World,
79
79
  authType: string
80
80
  ) => void
81
81
  ): void;
82
82
  declare function Then(
83
- pattern: "the API should handle the {word} request successfully",
83
+ pattern: "I see the API should handle the {word} request successfully",
84
84
  implementation: (
85
85
  this: import("@cucumber/cucumber").World,
86
86
  method: string,
@@ -18,12 +18,12 @@ const validateThreshold = (threshold) => {
18
18
  }
19
19
  };
20
20
 
21
- Given("I have a k6 script for {word} testing", function (method) {
21
+ Given("I set a k6 script for {word} testing", function (method) {
22
22
  this.config = { method: method.toUpperCase() };
23
23
  });
24
24
 
25
25
  When(
26
- "I run the k6 script with the following configurations:",
26
+ "I set to run the k6 script with the following configurations:",
27
27
  function (dataTable) {
28
28
  const row = dataTable.hashes()[0];
29
29
 
@@ -68,7 +68,7 @@ When(
68
68
  }
69
69
  }
70
70
  );
71
- When("the request headers are:", function (dataTable) {
71
+ When("I set the request headers:", function (dataTable) {
72
72
  const headers = {};
73
73
  dataTable.hashes().forEach(({ Header, Value }) => {
74
74
  headers[Header] = Value;
@@ -80,7 +80,7 @@ When("the request headers are:", function (dataTable) {
80
80
  };
81
81
  });
82
82
 
83
- When("the following endpoint\\(s) is\\/are used:", function (docString) {
83
+ When("I set the following endpoint\\(s) used:", function (docString) {
84
84
  this.config.endpoints = docString
85
85
  .trim()
86
86
  .split("\n")
@@ -88,7 +88,7 @@ When("the following endpoint\\(s) is\\/are used:", function (docString) {
88
88
  });
89
89
 
90
90
  When(
91
- "the following {word} body is used for {string}",
91
+ "I set the following {word} body is used for {string}",
92
92
  function (method, endpoint, docString) {
93
93
  this.config.method = method.toUpperCase();
94
94
  this.config.body = resolveBody(docString, process.env);
@@ -96,12 +96,12 @@ When(
96
96
  }
97
97
  );
98
98
 
99
- When("the authentication type is {string}", function (authType) {
99
+ When("I set the authentication type is {string}", function (authType) {
100
100
  this.config.headers = generateHeaders(authType, process.env);
101
101
  });
102
102
 
103
103
  Then(
104
- "the API should handle the {word} request successfully",
104
+ "I see the API should handle the {word} request successfully",
105
105
  { timeout: 60000 },
106
106
  async function (method) {
107
107
  if (!this.config || !this.config.method) {