playwright-cucumber-ts-steps 1.0.0 → 1.0.1
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.
- package/lib/actions/clickSteps.d.ts +251 -0
- package/lib/actions/clickSteps.js +415 -0
- package/lib/actions/cookieSteps.d.ts +18 -0
- package/lib/actions/cookieSteps.js +93 -0
- package/lib/actions/debugSteps.d.ts +14 -0
- package/lib/actions/debugSteps.js +23 -0
- package/lib/actions/elementFindSteps.d.ts +668 -0
- package/lib/actions/elementFindSteps.js +931 -0
- package/lib/actions/fillFormSteps.d.ts +69 -0
- package/lib/actions/fillFormSteps.js +237 -0
- package/lib/actions/index.d.ts +11 -0
- package/lib/actions/index.js +28 -0
- package/lib/actions/inputSteps.d.ts +218 -0
- package/lib/actions/inputSteps.js +343 -0
- package/lib/actions/interceptionSteps.d.ts +169 -0
- package/lib/actions/interceptionSteps.js +291 -0
- package/lib/actions/miscSteps.d.ts +645 -0
- package/lib/actions/miscSteps.js +1061 -0
- package/lib/actions/mouseSteps.d.ts +143 -0
- package/lib/actions/mouseSteps.js +234 -0
- package/lib/actions/scrollSteps.d.ts +82 -0
- package/lib/actions/scrollSteps.js +123 -0
- package/lib/actions/storageSteps.d.ts +174 -0
- package/lib/actions/storageSteps.js +292 -0
- package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +245 -0
- package/lib/assertions/buttonAndTextVisibilitySteps.js +401 -0
- package/lib/assertions/cookieSteps.d.ts +75 -0
- package/lib/assertions/cookieSteps.js +113 -0
- package/lib/assertions/elementSteps.d.ts +264 -0
- package/lib/assertions/elementSteps.js +388 -0
- package/lib/assertions/formInputSteps.d.ts +248 -0
- package/lib/assertions/formInputSteps.js +350 -0
- package/lib/assertions/index.d.ts +10 -0
- package/lib/assertions/index.js +27 -0
- package/lib/assertions/interceptionRequestsSteps.d.ts +353 -0
- package/lib/assertions/interceptionRequestsSteps.js +593 -0
- package/lib/assertions/locationSteps.d.ts +217 -0
- package/lib/assertions/locationSteps.js +310 -0
- package/lib/assertions/roleTestIdSteps.d.ts +159 -0
- package/lib/assertions/roleTestIdSteps.js +221 -0
- package/lib/assertions/semanticSteps.d.ts +176 -0
- package/lib/assertions/semanticSteps.js +252 -0
- package/lib/assertions/storageSteps.d.ts +149 -0
- package/lib/assertions/storageSteps.js +210 -0
- package/lib/assertions/visualSteps.d.ts +74 -0
- package/lib/assertions/visualSteps.js +209 -0
- package/lib/custom_setups/loginHooks.d.ts +1 -0
- package/lib/custom_setups/loginHooks.js +130 -0
- package/lib/helpers/checkPeerDeps.d.ts +1 -0
- package/lib/helpers/checkPeerDeps.js +19 -0
- package/lib/helpers/compareSnapshots.d.ts +6 -0
- package/lib/helpers/compareSnapshots.js +20 -0
- package/lib/helpers/hooks.d.ts +1 -0
- package/lib/helpers/hooks.js +210 -0
- package/lib/helpers/utils/fakerUtils.d.ts +1 -0
- package/lib/helpers/utils/fakerUtils.js +60 -0
- package/lib/helpers/utils/index.d.ts +4 -0
- package/lib/helpers/utils/index.js +20 -0
- package/lib/helpers/utils/optionsUtils.d.ts +24 -0
- package/lib/helpers/utils/optionsUtils.js +88 -0
- package/lib/helpers/utils/resolveUtils.d.ts +6 -0
- package/lib/helpers/utils/resolveUtils.js +72 -0
- package/lib/helpers/utils/sessionUtils.d.ts +3 -0
- package/lib/helpers/utils/sessionUtils.js +40 -0
- package/lib/helpers/world.d.ts +34 -0
- package/lib/helpers/world.js +110 -0
- package/lib/iframes/frames.d.ts +1 -0
- package/lib/iframes/frames.js +11 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +28 -0
- package/lib/register.d.ts +1 -0
- package/lib/register.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.When_I_type_random = exports.When_I_type_stored = exports.When_I_type = void 0;
|
|
4
|
+
exports.When_I_check = When_I_check;
|
|
5
|
+
exports.When_I_uncheck = When_I_uncheck;
|
|
6
|
+
exports.When_I_check_input = When_I_check_input;
|
|
7
|
+
exports.When_I_uncheck_input = When_I_uncheck_input;
|
|
8
|
+
exports.When_I_set_value = When_I_set_value;
|
|
9
|
+
exports.When_I_clear = When_I_clear;
|
|
10
|
+
exports.When_I_submit = When_I_submit;
|
|
11
|
+
exports.When_I_select_option = When_I_select_option;
|
|
12
|
+
exports.When_I_select_file = When_I_select_file;
|
|
13
|
+
// e2e/step_definitions/common/actions/inputSteps.ts
|
|
14
|
+
const cucumber_1 = require("@cucumber/cucumber");
|
|
15
|
+
const fakerUtils_1 = require("../helpers/utils/fakerUtils"); // Assuming this path is correct
|
|
16
|
+
const optionsUtils_1 = require("../helpers/utils/optionsUtils"); // Assuming this path is correct
|
|
17
|
+
// =============================
|
|
18
|
+
// WHEN I CHECK / UNCHECK
|
|
19
|
+
// =============================
|
|
20
|
+
/**
|
|
21
|
+
* Checks the previously selected element (e.g., a checkbox or radio button).
|
|
22
|
+
*
|
|
23
|
+
* ```gherkin
|
|
24
|
+
* When I check
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* When I find element by label text "Remember me"
|
|
29
|
+
* And I check
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
33
|
+
* to a checkbox or radio button. It will mark the element as checked. Optional Playwright
|
|
34
|
+
* `CheckOptions` can be provided via a data table.
|
|
35
|
+
*/
|
|
36
|
+
async function When_I_check(...rest) {
|
|
37
|
+
if (!this.element)
|
|
38
|
+
throw new Error("No element selected to check.");
|
|
39
|
+
const maybeTable = rest[0];
|
|
40
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
41
|
+
await this.element.check(options);
|
|
42
|
+
this.log?.("✅ Checked stored element.");
|
|
43
|
+
}
|
|
44
|
+
(0, cucumber_1.When)("I check", When_I_check);
|
|
45
|
+
/**
|
|
46
|
+
* Unchecks the previously selected element (e.g., a checkbox).
|
|
47
|
+
*
|
|
48
|
+
* ```gherkin
|
|
49
|
+
* When I uncheck
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* When I find element by label text "Agree to terms"
|
|
54
|
+
* And I uncheck
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
58
|
+
* to a checkbox. It will mark the element as unchecked. Optional Playwright
|
|
59
|
+
* `CheckOptions` can be provided via a data table.
|
|
60
|
+
*/
|
|
61
|
+
async function When_I_uncheck(...rest) {
|
|
62
|
+
if (!this.element)
|
|
63
|
+
throw new Error("No element selected to uncheck.");
|
|
64
|
+
const maybeTable = rest[0];
|
|
65
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
66
|
+
await this.element.uncheck(options);
|
|
67
|
+
this.log?.("✅ Unchecked stored element.");
|
|
68
|
+
}
|
|
69
|
+
(0, cucumber_1.When)("I uncheck", When_I_uncheck);
|
|
70
|
+
/**
|
|
71
|
+
* Checks a specific input element, requiring a preceding step to select it.
|
|
72
|
+
*
|
|
73
|
+
* ```gherkin
|
|
74
|
+
* When I check input
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* When I find element by selector "input#myCheckbox"
|
|
79
|
+
* And I check input
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This is an alias for "I check". It requires a preceding step that sets the
|
|
83
|
+
* {@link CustomWorld.element | current element} to an input element (like a checkbox or radio).
|
|
84
|
+
* Optional Playwright `CheckOptions` can be provided via a data table.
|
|
85
|
+
*/
|
|
86
|
+
async function When_I_check_input(...rest) {
|
|
87
|
+
if (!this.element)
|
|
88
|
+
throw new Error("No input selected to check.");
|
|
89
|
+
const maybeTable = rest[0];
|
|
90
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
91
|
+
await this.element.check(options);
|
|
92
|
+
this.log?.("✅ Checked stored input.");
|
|
93
|
+
}
|
|
94
|
+
(0, cucumber_1.When)("I check input", When_I_check_input);
|
|
95
|
+
/**
|
|
96
|
+
* Unchecks a specific input element, requiring a preceding step to select it.
|
|
97
|
+
*
|
|
98
|
+
* ```gherkin
|
|
99
|
+
* When I uncheck input
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* When I find element by selector "input#newsletter"
|
|
104
|
+
* And I uncheck input
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* This is an alias for "I uncheck". It requires a preceding step that sets the
|
|
108
|
+
* {@link CustomWorld.element | current element} to an input element (like a checkbox).
|
|
109
|
+
* Optional Playwright `CheckOptions` can be provided via a data table.
|
|
110
|
+
*/
|
|
111
|
+
async function When_I_uncheck_input(...rest) {
|
|
112
|
+
if (!this.element)
|
|
113
|
+
throw new Error("No input selected to uncheck.");
|
|
114
|
+
const maybeTable = rest[0];
|
|
115
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseCheckOptions)(maybeTable) : {};
|
|
116
|
+
await this.element.uncheck(options);
|
|
117
|
+
this.log?.("✅ Unchecked stored input.");
|
|
118
|
+
}
|
|
119
|
+
(0, cucumber_1.When)("I uncheck input", When_I_uncheck_input);
|
|
120
|
+
// =============================
|
|
121
|
+
// WHEN I TYPE / SET VALUE
|
|
122
|
+
// =============================
|
|
123
|
+
/**
|
|
124
|
+
* Shared implementation for typing steps.
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
const typeStepImplementation = async function (textOrAlias, ...rest) {
|
|
128
|
+
if (!this.element)
|
|
129
|
+
throw new Error("No element selected to type into.");
|
|
130
|
+
const maybeTable = rest[0];
|
|
131
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseFillOptions)(maybeTable) : {};
|
|
132
|
+
const text = textOrAlias.startsWith("@")
|
|
133
|
+
? (this.data[textOrAlias.slice(1)] ??
|
|
134
|
+
(() => {
|
|
135
|
+
throw new Error(`No value found for alias "${textOrAlias}".`);
|
|
136
|
+
})())
|
|
137
|
+
: (0, fakerUtils_1.evaluateFaker)(textOrAlias); // Evaluate faker directly here if it's not an alias
|
|
138
|
+
// Playwright's fill clears the field by default, but explicitly clearing can be safer
|
|
139
|
+
// await this.element.fill(""); // This explicit clear might not be necessary depending on Playwright version/behavior
|
|
140
|
+
await this.element.fill(text, options);
|
|
141
|
+
this.data.lastTyped = text; // Store the actual text typed for potential later use
|
|
142
|
+
this.log?.(`⌨️ Typed "${text}" into selected element.`);
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Types the given text into the previously selected element.
|
|
146
|
+
*
|
|
147
|
+
* ```gherkin
|
|
148
|
+
* When I type {string}
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* When I find element by selector "input[name='email']"
|
|
153
|
+
* And I type "user@example.com"
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
157
|
+
* to an input field (or any element that supports `fill`). The provided text can be a literal
|
|
158
|
+
* string or a faker expression (e.g., `{{internet.email}}`).
|
|
159
|
+
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
160
|
+
*/
|
|
161
|
+
exports.When_I_type = typeStepImplementation;
|
|
162
|
+
(0, cucumber_1.When)("I type {string}", exports.When_I_type);
|
|
163
|
+
/**
|
|
164
|
+
* Types the value stored in an alias into the previously selected element.
|
|
165
|
+
*
|
|
166
|
+
* ```gherkin
|
|
167
|
+
* When I type stored {string}
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* Given I store "my.user@example.com" as "userEmail"
|
|
172
|
+
* When I find element by selector "input[name='email']"
|
|
173
|
+
* And I type stored "userEmail"
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
177
|
+
* to an input field. The `string` argument must be an alias (e.g., `userEmail`).
|
|
178
|
+
* The value associated with this alias in `this.data` will be typed into the element.
|
|
179
|
+
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
180
|
+
*/
|
|
181
|
+
exports.When_I_type_stored = typeStepImplementation;
|
|
182
|
+
(0, cucumber_1.When)("I type stored {string}", exports.When_I_type_stored);
|
|
183
|
+
/**
|
|
184
|
+
* Types a randomly generated value (using Faker.js) into the previously selected element.
|
|
185
|
+
*
|
|
186
|
+
* ```gherkin
|
|
187
|
+
* When I type random {string}
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* When I find element by selector "input[name='username']"
|
|
192
|
+
* And I type random "internet.userName"
|
|
193
|
+
*
|
|
194
|
+
* @remarks
|
|
195
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
196
|
+
* to an input field. The `string` argument should be a Faker.js path (e.g., `internet.email`,
|
|
197
|
+
* `person.firstName`). A random value generated by Faker will be typed into the element.
|
|
198
|
+
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
199
|
+
*/
|
|
200
|
+
exports.When_I_type_random = typeStepImplementation;
|
|
201
|
+
(0, cucumber_1.When)("I type random {string}", exports.When_I_type_random);
|
|
202
|
+
/**
|
|
203
|
+
* Sets the value of the previously selected element.
|
|
204
|
+
*
|
|
205
|
+
* ```gherkin
|
|
206
|
+
* When I set value {string}
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* When I find element by selector "input[name='password']"
|
|
211
|
+
* And I set value "@userPassword"
|
|
212
|
+
*
|
|
213
|
+
* @remarks
|
|
214
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
215
|
+
* to an input field (or any element that supports `fill`). The provided `valueOrAlias` can be
|
|
216
|
+
* a literal string, an alias (prefixed with `@`), or a Faker expression. This will directly
|
|
217
|
+
* set the input's value, which is generally faster than typing for non-interactive scenarios.
|
|
218
|
+
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
219
|
+
*/
|
|
220
|
+
async function When_I_set_value(valueOrAlias, ...rest) {
|
|
221
|
+
if (!this.element)
|
|
222
|
+
throw new Error("No element selected to set value.");
|
|
223
|
+
const maybeTable = rest[0];
|
|
224
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseFillOptions)(maybeTable) : {};
|
|
225
|
+
const value = valueOrAlias.startsWith("@")
|
|
226
|
+
? (this.data[valueOrAlias.slice(1)] ??
|
|
227
|
+
(() => {
|
|
228
|
+
throw new Error(`No value found for alias "${valueOrAlias}".`);
|
|
229
|
+
})())
|
|
230
|
+
: (0, fakerUtils_1.evaluateFaker)(valueOrAlias); // Evaluate faker directly here if it's not an alias
|
|
231
|
+
await this.element.fill(value, options);
|
|
232
|
+
this.data.lastValueSet = value; // Store the actual value set for potential later use
|
|
233
|
+
this.log?.(`📝 Set value of selected element to "${value}".`);
|
|
234
|
+
}
|
|
235
|
+
(0, cucumber_1.When)("I set value {string}", When_I_set_value);
|
|
236
|
+
/**
|
|
237
|
+
* Clears the value of the previously selected element.
|
|
238
|
+
*
|
|
239
|
+
* ```gherkin
|
|
240
|
+
* When I clear
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* When I find element by selector "input[name='search']"
|
|
245
|
+
* And I clear
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
249
|
+
* to an input field (or any element that supports `fill`). It effectively empties the input field.
|
|
250
|
+
*/
|
|
251
|
+
async function When_I_clear() {
|
|
252
|
+
if (!this.element)
|
|
253
|
+
throw new Error("No element selected to clear.");
|
|
254
|
+
await this.element.fill("");
|
|
255
|
+
this.log?.("🧼 Cleared value of selected element.");
|
|
256
|
+
}
|
|
257
|
+
(0, cucumber_1.When)("I clear", When_I_clear);
|
|
258
|
+
/**
|
|
259
|
+
* Submits the form associated with the previously selected element, or the first form on the page.
|
|
260
|
+
*
|
|
261
|
+
* ```gherkin
|
|
262
|
+
* When I submit
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* When I find element by selector "form#loginForm"
|
|
267
|
+
* And I submit
|
|
268
|
+
* # OR (submits the first form found if no element is selected)
|
|
269
|
+
* When I go to "/login"
|
|
270
|
+
* And I submit
|
|
271
|
+
*
|
|
272
|
+
* @remarks
|
|
273
|
+
* This step will find a form to submit. If {@link CustomWorld.element | this.element}
|
|
274
|
+
* is a form or an element within a form, that form will be submitted. Otherwise, it will
|
|
275
|
+
* attempt to submit the first `<form>` element found on the page.
|
|
276
|
+
* It uses a direct DOM `submit()` call, which bypasses Playwright's default event handling
|
|
277
|
+
* and can be useful for testing native form submission behavior.
|
|
278
|
+
*/
|
|
279
|
+
async function When_I_submit() {
|
|
280
|
+
// Use the current element if it's a form or within a form, otherwise default to the first form on the page.
|
|
281
|
+
const formLocator = this.element
|
|
282
|
+
? this.element.locator("xpath=ancestor-or-self::form")
|
|
283
|
+
: this.page.locator("form").first();
|
|
284
|
+
if (!(await formLocator.isVisible())) {
|
|
285
|
+
throw new Error("No visible form found to submit. Ensure an element within a form is selected, or a form exists on the page.");
|
|
286
|
+
}
|
|
287
|
+
await formLocator.evaluate((f) => f.submit());
|
|
288
|
+
this.log?.("📨 Submitted form.");
|
|
289
|
+
}
|
|
290
|
+
(0, cucumber_1.When)("I submit", When_I_submit);
|
|
291
|
+
/**
|
|
292
|
+
* Selects an option by its visible text label in a `<select>` element.
|
|
293
|
+
*
|
|
294
|
+
* ```gherkin
|
|
295
|
+
* When I select option {string}
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* When I find element by selector "select[name='role']"
|
|
300
|
+
* And I select option "Administrator"
|
|
301
|
+
*
|
|
302
|
+
* @remarks
|
|
303
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
304
|
+
* to a `<select>` HTML element. It will then select the option whose visible text matches
|
|
305
|
+
* the provided `option` string.
|
|
306
|
+
* Optional Playwright `SelectOptionOptions` can be provided via a data table.
|
|
307
|
+
*/
|
|
308
|
+
async function When_I_select_option(option, ...rest) {
|
|
309
|
+
if (!this.element)
|
|
310
|
+
throw new Error("No select element stored to select an option.");
|
|
311
|
+
const maybeTable = rest[0];
|
|
312
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseSelectOptions)(maybeTable) : {};
|
|
313
|
+
await this.element.selectOption({ label: option }, options);
|
|
314
|
+
this.log?.(`🔽 Selected option "${option}".`);
|
|
315
|
+
}
|
|
316
|
+
(0, cucumber_1.When)("I select option {string}", When_I_select_option);
|
|
317
|
+
/**
|
|
318
|
+
* Sets the file input of the previously selected element to the specified file path.
|
|
319
|
+
*
|
|
320
|
+
* ```gherkin
|
|
321
|
+
* When I select file {string}
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* When I find element by selector "input[type='file']"
|
|
326
|
+
* And I select file "path/to/my/document.pdf"
|
|
327
|
+
*
|
|
328
|
+
* @remarks
|
|
329
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
330
|
+
* to an `input` element of `type="file"`. The `filePath` should be relative to your project's
|
|
331
|
+
* root or an absolute path. Playwright will automatically handle making the file available
|
|
332
|
+
* for upload.
|
|
333
|
+
* Optional Playwright `SetInputFilesOptions` can be provided via a data table.
|
|
334
|
+
*/
|
|
335
|
+
async function When_I_select_file(filePath, ...rest) {
|
|
336
|
+
if (!this.element)
|
|
337
|
+
throw new Error("No file input selected to set a file.");
|
|
338
|
+
const maybeTable = rest[0];
|
|
339
|
+
const options = maybeTable?.rowsHash ? (0, optionsUtils_1.parseSelectOptions)(maybeTable) : {}; // Note: parseSelectOptions is used here, assuming it returns `SetInputFilesOptions` compatible object or is generic enough. If not, a new parser for SetInputFilesOptions would be ideal.
|
|
340
|
+
await this.element.setInputFiles(filePath, options);
|
|
341
|
+
this.log?.(`📁 Set input file to "${filePath}".`);
|
|
342
|
+
}
|
|
343
|
+
(0, cucumber_1.When)("I select file {string}", When_I_select_file);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { DataTable } from "@cucumber/cucumber";
|
|
2
|
+
import { CustomWorld } from "../helpers/world";
|
|
3
|
+
/**
|
|
4
|
+
* Intercepts a network request to the given URL and stubs its response body with the provided JSON.
|
|
5
|
+
* This step should be used *before* the action that triggers the request (e.g., navigating to a page
|
|
6
|
+
* or clicking a button that makes an API call).
|
|
7
|
+
*
|
|
8
|
+
* ```gherkin
|
|
9
|
+
* When I intercept URL {string} and stub body:
|
|
10
|
+
* """
|
|
11
|
+
* { "foo": "bar" }
|
|
12
|
+
* """
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param url - The URL to intercept. This can be a full URL, a URL glob, or a regular expression string.
|
|
16
|
+
* @param body - A DocString containing the JSON string to use as the response body.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Scenario: Stubbing an API response
|
|
20
|
+
* When I intercept URL "https://api.example.com/data" and stub body:
|
|
21
|
+
* """
|
|
22
|
+
* { "status": "success", "items": ["item1", "item2"] }
|
|
23
|
+
* """
|
|
24
|
+
* And I go to "/dashboard"
|
|
25
|
+
* Then I should see text "item1"
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* The intercepted request will respond with a `200 OK` status and a `Content-Type` of `application/json`.
|
|
29
|
+
* The `body` provided must be valid JSON. Playwright's `page.route()` is used internally.
|
|
30
|
+
* Make sure this step executes *before* the network request is initiated.
|
|
31
|
+
* @category Network Interception Steps
|
|
32
|
+
*/
|
|
33
|
+
export declare function When_I_intercept_URL_and_stub_body(this: CustomWorld, url: string, body: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Intercepts a network request to the given URL and allows it to continue unmodified.
|
|
36
|
+
* This can be useful for ensuring that specific requests are *not* blocked or for logging
|
|
37
|
+
* requests without altering their behavior.
|
|
38
|
+
*
|
|
39
|
+
* ```gherkin
|
|
40
|
+
* When I intercept URL {string}
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param url - The URL to intercept. This can be a full URL, a URL glob, or a regular expression string.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* Scenario: Allowing a specific request to pass through
|
|
47
|
+
* When I intercept URL "https://analytics.example.com/*"
|
|
48
|
+
* And I go to "/dashboard"
|
|
49
|
+
* Then the page title should be "Dashboard"
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* This step uses Playwright's `page.route()` with `route.continue()`. No changes are made
|
|
53
|
+
* to the request or its response. This is essentially a "monitor" step.
|
|
54
|
+
* @category Network Interception Steps
|
|
55
|
+
*/
|
|
56
|
+
export declare function When_I_intercept_URL(this: CustomWorld, url: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Intercepts a network request to the given URL and stubs its response body with a raw string.
|
|
59
|
+
* This is useful for returning non-JSON content or simple string responses.
|
|
60
|
+
*
|
|
61
|
+
* ```gherkin
|
|
62
|
+
* When I intercept URL {string} and stub body {string}
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param url - The URL to intercept. This can be a full URL, a URL glob, or a regular expression string.
|
|
66
|
+
* @param body - The raw string content to use as the response body.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* Scenario: Stubbing a simple text response
|
|
70
|
+
* When I intercept URL "https://api.example.com/status" and stub body "OK"
|
|
71
|
+
* And I visit page with JS that fetches "/status"
|
|
72
|
+
* Then I should see text "OK"
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* The intercepted request will respond with a `200 OK` status and a `Content-Type` of `application/json`
|
|
76
|
+
* by default (though the `body` is a raw string). If a different `contentType` is needed, consider
|
|
77
|
+
* using the `I intercept URL {string} and stub response with:` step if available, or extending this step.
|
|
78
|
+
* @category Network Interception Steps
|
|
79
|
+
*/
|
|
80
|
+
export declare function When_I_intercept_URL_and_stub_raw_body(this: CustomWorld, url: string, body: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Makes a GET request to the given URL and stores the response details (status and body)
|
|
83
|
+
* in the test context.
|
|
84
|
+
*
|
|
85
|
+
* ```gherkin
|
|
86
|
+
* When I make request to {string}
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param url - The URL to which the GET request will be made.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* Scenario: Verify API endpoint status
|
|
93
|
+
* When I make request to "https://api.example.com/health"
|
|
94
|
+
* Then the last response status should be 200
|
|
95
|
+
* And the last response body should contain "healthy"
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* The response object (including status and body) is stored in
|
|
99
|
+
* {@link CustomWorld.data.lastResponse | this.data.lastResponse}. Subsequent assertion steps
|
|
100
|
+
* can then access this data.
|
|
101
|
+
* @category API Request Steps
|
|
102
|
+
*/
|
|
103
|
+
export declare function When_I_make_GET_request_to(this: CustomWorld, url: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Makes a POST request to the given URL with the provided JSON body and stores the response details.
|
|
106
|
+
*
|
|
107
|
+
* ```gherkin
|
|
108
|
+
* When I make a POST request to {string} with JSON body:
|
|
109
|
+
* """
|
|
110
|
+
* { "username": "user", "password": "pass" }
|
|
111
|
+
* """
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param url - The URL to which the POST request will be made.
|
|
115
|
+
* @param docString - A Cucumber DocString containing the JSON payload for the request body.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* Scenario: Login via API
|
|
119
|
+
* When I make a POST request to "https://api.example.com/login" with JSON body:
|
|
120
|
+
* """
|
|
121
|
+
* { "email": "test@example.com", "password": "password123" }
|
|
122
|
+
* """
|
|
123
|
+
* Then the last response status should be 200
|
|
124
|
+
* And the last response body should contain "token"
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* The `docString` must contain valid JSON. The request will have a `Content-Type` of `application/json`.
|
|
128
|
+
* The response object (including status and body) is stored in
|
|
129
|
+
* {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
|
|
130
|
+
* @category API Request Steps
|
|
131
|
+
*/
|
|
132
|
+
export declare function When_I_make_POST_request_with_JSON_body(this: CustomWorld, url: string, docString: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Makes a generic HTTP request with a specified method and optional headers/body from a data table.
|
|
135
|
+
*
|
|
136
|
+
* ```gherkin
|
|
137
|
+
* When I make a "{word}" request to {string}
|
|
138
|
+
* | header | value |
|
|
139
|
+
* | Content-Type | application/json |
|
|
140
|
+
* | ... | ... |
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param method - The HTTP method (e.g., "GET", "POST", "PUT", "DELETE").
|
|
144
|
+
* @param url - The URL for the request.
|
|
145
|
+
* @param table - (Optional) A Cucumber DataTable with `header` and `value` columns for headers,
|
|
146
|
+
* and a `body` row for the request body.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* Scenario: Make a PUT request with custom headers
|
|
150
|
+
* When I make a "PUT" request to "https://api.example.com/resource/123"
|
|
151
|
+
* | Content-Type | application/json |
|
|
152
|
+
* | Authorization | Bearer my-token |
|
|
153
|
+
* | body | { "status": "updated" } |
|
|
154
|
+
* Then the last response status should be 200
|
|
155
|
+
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* This step constructs a `fetch` request using the provided method, URL, and options from the
|
|
158
|
+
* data table. The `body` provided in the data table (if any) will be automatically
|
|
159
|
+
* JSON.parsed and then JSON.stringified. The entire `Response` object from `fetch` is
|
|
160
|
+
* stored in {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
|
|
161
|
+
*
|
|
162
|
+
* **Note on `fetch`:** This step uses the browser's `fetch` API, which runs in the browser context.
|
|
163
|
+
* If you need to make Node.js-based requests (e.g., for backend APIs that are not accessible from the browser),
|
|
164
|
+
* you might prefer `page.request` (as used in `When_I_make_GET_request_to` or `When_I_make_POST_request_with_JSON_body`).
|
|
165
|
+
* This step stores the raw `Response` object, so you might need to call `.json()` or `.text()`
|
|
166
|
+
* on `this.data.lastResponse` in subsequent steps if you need to assert on its content.
|
|
167
|
+
* @category API Request Steps
|
|
168
|
+
*/
|
|
169
|
+
export declare function When_I_make_HTTP_request_with_options(this: CustomWorld, method: string, url: string, table?: DataTable): Promise<void>;
|