playwright-cucumber-ts-steps 1.0.1 → 1.0.2
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/README.md +195 -256
- package/dist/backend/actions/index.js +4 -0
- package/dist/backend/actions/interactions.js +23 -0
- package/dist/backend/actions/navigation.js +19 -0
- package/dist/backend/api/assertions.js +26 -0
- package/dist/backend/api/index.js +4 -0
- package/dist/backend/api/requests.js +24 -0
- package/dist/backend/api/state.js +15 -0
- package/dist/backend/assertions/expectVisible.js +8 -0
- package/dist/backend/assertions/index.js +5 -0
- package/dist/backend/assertions/pageState.js +25 -0
- package/dist/backend/assertions/text.js +20 -0
- package/dist/backend/assertions/visibility.js +20 -0
- package/dist/backend/auth/index.js +71 -0
- package/dist/backend/elements/alerts.js +21 -0
- package/dist/backend/elements/forms.js +59 -0
- package/dist/backend/elements/frames.js +25 -0
- package/dist/backend/elements/index.js +5 -0
- package/dist/core/registry.js +20 -0
- package/dist/core/runner.js +136 -0
- package/dist/index.js +10 -0
- package/dist/reporting/index.js +43 -0
- package/package.json +19 -101
- package/LICENSE +0 -21
- package/lib/actions/clickSteps.d.ts +0 -251
- package/lib/actions/clickSteps.js +0 -415
- package/lib/actions/cookieSteps.d.ts +0 -18
- package/lib/actions/cookieSteps.js +0 -93
- package/lib/actions/debugSteps.d.ts +0 -14
- package/lib/actions/debugSteps.js +0 -23
- package/lib/actions/elementFindSteps.d.ts +0 -668
- package/lib/actions/elementFindSteps.js +0 -931
- package/lib/actions/fillFormSteps.d.ts +0 -69
- package/lib/actions/fillFormSteps.js +0 -237
- package/lib/actions/index.d.ts +0 -11
- package/lib/actions/index.js +0 -28
- package/lib/actions/inputSteps.d.ts +0 -218
- package/lib/actions/inputSteps.js +0 -343
- package/lib/actions/interceptionSteps.d.ts +0 -169
- package/lib/actions/interceptionSteps.js +0 -291
- package/lib/actions/miscSteps.d.ts +0 -645
- package/lib/actions/miscSteps.js +0 -1061
- package/lib/actions/mouseSteps.d.ts +0 -143
- package/lib/actions/mouseSteps.js +0 -234
- package/lib/actions/scrollSteps.d.ts +0 -82
- package/lib/actions/scrollSteps.js +0 -123
- package/lib/actions/storageSteps.d.ts +0 -174
- package/lib/actions/storageSteps.js +0 -292
- package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -245
- package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -401
- package/lib/assertions/cookieSteps.d.ts +0 -75
- package/lib/assertions/cookieSteps.js +0 -113
- package/lib/assertions/elementSteps.d.ts +0 -264
- package/lib/assertions/elementSteps.js +0 -388
- package/lib/assertions/formInputSteps.d.ts +0 -248
- package/lib/assertions/formInputSteps.js +0 -350
- package/lib/assertions/index.d.ts +0 -10
- package/lib/assertions/index.js +0 -27
- package/lib/assertions/interceptionRequestsSteps.d.ts +0 -353
- package/lib/assertions/interceptionRequestsSteps.js +0 -593
- package/lib/assertions/locationSteps.d.ts +0 -217
- package/lib/assertions/locationSteps.js +0 -310
- package/lib/assertions/roleTestIdSteps.d.ts +0 -159
- package/lib/assertions/roleTestIdSteps.js +0 -221
- package/lib/assertions/semanticSteps.d.ts +0 -176
- package/lib/assertions/semanticSteps.js +0 -252
- package/lib/assertions/storageSteps.d.ts +0 -149
- package/lib/assertions/storageSteps.js +0 -210
- package/lib/assertions/visualSteps.d.ts +0 -74
- package/lib/assertions/visualSteps.js +0 -209
- package/lib/custom_setups/loginHooks.d.ts +0 -1
- package/lib/custom_setups/loginHooks.js +0 -130
- package/lib/helpers/checkPeerDeps.d.ts +0 -1
- package/lib/helpers/checkPeerDeps.js +0 -19
- package/lib/helpers/compareSnapshots.d.ts +0 -6
- package/lib/helpers/compareSnapshots.js +0 -20
- package/lib/helpers/hooks.d.ts +0 -1
- package/lib/helpers/hooks.js +0 -210
- package/lib/helpers/utils/fakerUtils.d.ts +0 -1
- package/lib/helpers/utils/fakerUtils.js +0 -60
- package/lib/helpers/utils/index.d.ts +0 -4
- package/lib/helpers/utils/index.js +0 -20
- package/lib/helpers/utils/optionsUtils.d.ts +0 -24
- package/lib/helpers/utils/optionsUtils.js +0 -88
- package/lib/helpers/utils/resolveUtils.d.ts +0 -6
- package/lib/helpers/utils/resolveUtils.js +0 -72
- package/lib/helpers/utils/sessionUtils.d.ts +0 -3
- package/lib/helpers/utils/sessionUtils.js +0 -40
- package/lib/helpers/world.d.ts +0 -34
- package/lib/helpers/world.js +0 -110
- package/lib/iframes/frames.d.ts +0 -1
- package/lib/iframes/frames.js +0 -11
- package/lib/index.d.ts +0 -10
- package/lib/index.js +0 -28
- package/lib/register.d.ts +0 -1
- package/lib/register.js +0 -6
- package/src/actions/clickSteps.ts +0 -429
- package/src/actions/cookieSteps.ts +0 -95
- package/src/actions/debugSteps.ts +0 -21
- package/src/actions/elementFindSteps.ts +0 -961
- package/src/actions/fillFormSteps.ts +0 -270
- package/src/actions/index.ts +0 -12
- package/src/actions/inputSteps.ts +0 -354
- package/src/actions/interceptionSteps.ts +0 -325
- package/src/actions/miscSteps.ts +0 -1144
- package/src/actions/mouseSteps.ts +0 -256
- package/src/actions/scrollSteps.ts +0 -122
- package/src/actions/storageSteps.ts +0 -308
- package/src/assertions/buttonAndTextVisibilitySteps.ts +0 -436
- package/src/assertions/cookieSteps.ts +0 -131
- package/src/assertions/elementSteps.ts +0 -432
- package/src/assertions/formInputSteps.ts +0 -377
- package/src/assertions/index.ts +0 -11
- package/src/assertions/interceptionRequestsSteps.ts +0 -640
- package/src/assertions/locationSteps.ts +0 -315
- package/src/assertions/roleTestIdSteps.ts +0 -254
- package/src/assertions/semanticSteps.ts +0 -267
- package/src/assertions/storageSteps.ts +0 -250
- package/src/assertions/visualSteps.ts +0 -275
- package/src/custom_setups/loginHooks.ts +0 -154
- package/src/helpers/checkPeerDeps.ts +0 -19
- package/src/helpers/compareSnapshots.ts +0 -35
- package/src/helpers/hooks.ts +0 -212
- package/src/helpers/utils/fakerUtils.ts +0 -64
- package/src/helpers/utils/index.ts +0 -4
- package/src/helpers/utils/optionsUtils.ts +0 -104
- package/src/helpers/utils/resolveUtils.ts +0 -74
- package/src/helpers/utils/sessionUtils.ts +0 -36
- package/src/helpers/world.ts +0 -119
- package/src/iframes/frames.ts +0 -15
- package/src/index.ts +0 -18
- package/src/register.ts +0 -4
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { CustomWorld } from "../helpers/world";
|
|
2
|
-
/**
|
|
3
|
-
* Fills a form using a data table, supporting various interactions and assertions.
|
|
4
|
-
* This is a highly versatile step designed to encapsulate multiple form-related
|
|
5
|
-
* actions, including filling inputs, clicking elements, checking checkboxes,
|
|
6
|
-
* uploading files, performing drag-and-drop, managing browser storage,
|
|
7
|
-
* initiating API requests, and making UI assertions.
|
|
8
|
-
*
|
|
9
|
-
* ```gherkin
|
|
10
|
-
* When I fill the following {string} form data:
|
|
11
|
-
* | Target | Value |
|
|
12
|
-
* | input[placeholder='email'] | test@email.com |
|
|
13
|
-
* | input[placeholder='password'] | @adminPassword |
|
|
14
|
-
* | input[type='checkbox'] | check |
|
|
15
|
-
* | select[name='role'] | select |
|
|
16
|
-
* | button:has-text("Sign In") | click |
|
|
17
|
-
* | .dashboard-header | assert:visible |
|
|
18
|
-
* | .user-role | assert:text:Admin |
|
|
19
|
-
* | input[type='file'] | upload:fixtures/profile-pic.jpg |
|
|
20
|
-
* | div.upload-target | drag:.upload-preview |
|
|
21
|
-
* | request:POST:/api/auth/login | payload:adminLogin.json | SaveAs:loginResponse |
|
|
22
|
-
* | set:localStorage:auth_token | @lastApiResponse.token |
|
|
23
|
-
* | wait | wait:1000 |
|
|
24
|
-
* | reload | |
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @param formName - A descriptive name for the form (e.g., "Login", "Profile").
|
|
28
|
-
* This is currently for documentation purposes only.
|
|
29
|
-
* @param dataTable - A Cucumber data table containing 'Target' and 'Value' columns.
|
|
30
|
-
* Optionally, 'PayloadDir' and 'SaveAs' columns can be used for API requests.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* Each row in the data table represents an action to perform. The `Target` column
|
|
34
|
-
* typically specifies a CSS selector for an element, but can also define special
|
|
35
|
-
* actions like `request:`, `set:localStorage:`, `set:sessionStorage:`, `wait`, and `reload`.
|
|
36
|
-
* The `Value` column defines the action or input for the target.
|
|
37
|
-
*
|
|
38
|
-
* **Supported `Value` actions:**
|
|
39
|
-
* - **`fill_value` (default):** Fills the target input with the given value. Supports aliases
|
|
40
|
-
* resolved via `resolveLoginValue`.
|
|
41
|
-
* - **`click`:** Clicks the target element.
|
|
42
|
-
* - **`check`:** Checks a checkbox or radio button.
|
|
43
|
-
* - **`uncheck`:** Unchecks a checkbox.
|
|
44
|
-
* - **`select`:** Selects the first option in a dropdown (e.g., `<select>`).
|
|
45
|
-
* - **`upload:filepath`:** Uploads a file from the `filepath` (relative to project root).
|
|
46
|
-
* Example: `upload:fixtures/my-image.png`
|
|
47
|
-
* - **`drag:target_selector`:** Drags the `Target` element to the element specified by `target_selector`.
|
|
48
|
-
* - **`assert:type:expected_value`:** Performs an assertion on the `Target` element.
|
|
49
|
-
* - `assert:visible`: Asserts the element is visible.
|
|
50
|
-
* - `assert:text:expected_text`: Asserts the element has the exact text.
|
|
51
|
-
* - `assert:value:expected_value`: Asserts an input/textarea has the exact value.
|
|
52
|
-
* - **`request:METHOD:url`:** Makes an API request.
|
|
53
|
-
* - `METHOD` can be `POST`, `GET`, `PUT`, `PATCH`.
|
|
54
|
-
* - `url` is the API endpoint.
|
|
55
|
-
* - **Requires additional columns:** `PayloadDir` (optional, default 'payload')
|
|
56
|
-
* and `Payload` (filename, e.g., `adminLogin.json`).
|
|
57
|
-
* - **Optional `SaveAs` column:** Saves the API response body to `this.data[SaveAs]`.
|
|
58
|
-
* - The response body is also stored in `this.data.lastApiResponse`.
|
|
59
|
-
* - **`set:localStorage:key`:** Sets a value in `localStorage`.
|
|
60
|
-
* The `Value` column provides the value to set, supporting aliases.
|
|
61
|
-
* - **`set:sessionStorage:key`:** Sets a value in `sessionStorage`.
|
|
62
|
-
* The `Value` column provides the value to set, supporting aliases.
|
|
63
|
-
* - **`wait:milliseconds`:** Pauses execution for the specified milliseconds.
|
|
64
|
-
* - **`reload`:** Reloads the current page.
|
|
65
|
-
*
|
|
66
|
-
* @category Form Interaction Steps
|
|
67
|
-
*/
|
|
68
|
-
export declare function When_I_fill_the_following_form_data(this: CustomWorld, _formName: string, // Renamed to _formName as it's not used in logic, just for readability in Gherkin
|
|
69
|
-
dataTable: any): Promise<void>;
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.When_I_fill_the_following_form_data = When_I_fill_the_following_form_data;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
10
|
-
const test_1 = require("@playwright/test");
|
|
11
|
-
const resolveUtils_1 = require("../helpers/utils/resolveUtils"); // Assuming this path is correct
|
|
12
|
-
/**
|
|
13
|
-
* Fills a form using a data table, supporting various interactions and assertions.
|
|
14
|
-
* This is a highly versatile step designed to encapsulate multiple form-related
|
|
15
|
-
* actions, including filling inputs, clicking elements, checking checkboxes,
|
|
16
|
-
* uploading files, performing drag-and-drop, managing browser storage,
|
|
17
|
-
* initiating API requests, and making UI assertions.
|
|
18
|
-
*
|
|
19
|
-
* ```gherkin
|
|
20
|
-
* When I fill the following {string} form data:
|
|
21
|
-
* | Target | Value |
|
|
22
|
-
* | input[placeholder='email'] | test@email.com |
|
|
23
|
-
* | input[placeholder='password'] | @adminPassword |
|
|
24
|
-
* | input[type='checkbox'] | check |
|
|
25
|
-
* | select[name='role'] | select |
|
|
26
|
-
* | button:has-text("Sign In") | click |
|
|
27
|
-
* | .dashboard-header | assert:visible |
|
|
28
|
-
* | .user-role | assert:text:Admin |
|
|
29
|
-
* | input[type='file'] | upload:fixtures/profile-pic.jpg |
|
|
30
|
-
* | div.upload-target | drag:.upload-preview |
|
|
31
|
-
* | request:POST:/api/auth/login | payload:adminLogin.json | SaveAs:loginResponse |
|
|
32
|
-
* | set:localStorage:auth_token | @lastApiResponse.token |
|
|
33
|
-
* | wait | wait:1000 |
|
|
34
|
-
* | reload | |
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param formName - A descriptive name for the form (e.g., "Login", "Profile").
|
|
38
|
-
* This is currently for documentation purposes only.
|
|
39
|
-
* @param dataTable - A Cucumber data table containing 'Target' and 'Value' columns.
|
|
40
|
-
* Optionally, 'PayloadDir' and 'SaveAs' columns can be used for API requests.
|
|
41
|
-
*
|
|
42
|
-
* @remarks
|
|
43
|
-
* Each row in the data table represents an action to perform. The `Target` column
|
|
44
|
-
* typically specifies a CSS selector for an element, but can also define special
|
|
45
|
-
* actions like `request:`, `set:localStorage:`, `set:sessionStorage:`, `wait`, and `reload`.
|
|
46
|
-
* The `Value` column defines the action or input for the target.
|
|
47
|
-
*
|
|
48
|
-
* **Supported `Value` actions:**
|
|
49
|
-
* - **`fill_value` (default):** Fills the target input with the given value. Supports aliases
|
|
50
|
-
* resolved via `resolveLoginValue`.
|
|
51
|
-
* - **`click`:** Clicks the target element.
|
|
52
|
-
* - **`check`:** Checks a checkbox or radio button.
|
|
53
|
-
* - **`uncheck`:** Unchecks a checkbox.
|
|
54
|
-
* - **`select`:** Selects the first option in a dropdown (e.g., `<select>`).
|
|
55
|
-
* - **`upload:filepath`:** Uploads a file from the `filepath` (relative to project root).
|
|
56
|
-
* Example: `upload:fixtures/my-image.png`
|
|
57
|
-
* - **`drag:target_selector`:** Drags the `Target` element to the element specified by `target_selector`.
|
|
58
|
-
* - **`assert:type:expected_value`:** Performs an assertion on the `Target` element.
|
|
59
|
-
* - `assert:visible`: Asserts the element is visible.
|
|
60
|
-
* - `assert:text:expected_text`: Asserts the element has the exact text.
|
|
61
|
-
* - `assert:value:expected_value`: Asserts an input/textarea has the exact value.
|
|
62
|
-
* - **`request:METHOD:url`:** Makes an API request.
|
|
63
|
-
* - `METHOD` can be `POST`, `GET`, `PUT`, `PATCH`.
|
|
64
|
-
* - `url` is the API endpoint.
|
|
65
|
-
* - **Requires additional columns:** `PayloadDir` (optional, default 'payload')
|
|
66
|
-
* and `Payload` (filename, e.g., `adminLogin.json`).
|
|
67
|
-
* - **Optional `SaveAs` column:** Saves the API response body to `this.data[SaveAs]`.
|
|
68
|
-
* - The response body is also stored in `this.data.lastApiResponse`.
|
|
69
|
-
* - **`set:localStorage:key`:** Sets a value in `localStorage`.
|
|
70
|
-
* The `Value` column provides the value to set, supporting aliases.
|
|
71
|
-
* - **`set:sessionStorage:key`:** Sets a value in `sessionStorage`.
|
|
72
|
-
* The `Value` column provides the value to set, supporting aliases.
|
|
73
|
-
* - **`wait:milliseconds`:** Pauses execution for the specified milliseconds.
|
|
74
|
-
* - **`reload`:** Reloads the current page.
|
|
75
|
-
*
|
|
76
|
-
* @category Form Interaction Steps
|
|
77
|
-
*/
|
|
78
|
-
async function When_I_fill_the_following_form_data(_formName, // Renamed to _formName as it's not used in logic, just for readability in Gherkin
|
|
79
|
-
dataTable // Use `any` for dataTable as its structure is defined by `hashes()`
|
|
80
|
-
) {
|
|
81
|
-
const rows = dataTable.hashes();
|
|
82
|
-
for (const row of rows) {
|
|
83
|
-
const target = row.Target.trim();
|
|
84
|
-
const rawValue = row.Value.trim();
|
|
85
|
-
// Resolve value early if it's not an action that prevents it (like `click`)
|
|
86
|
-
(0, resolveUtils_1.resolveLoginValue)(rawValue, this);
|
|
87
|
-
// --- Special Actions (not directly on a locator) ---
|
|
88
|
-
// ✅ Request handling (e.g., `request:POST:/api/auth/login`)
|
|
89
|
-
if (target.startsWith("request:")) {
|
|
90
|
-
const [, method, url] = target.replace("request:", "").split(":");
|
|
91
|
-
const payloadFile = rawValue.trim(); // Value column now holds the payload filename
|
|
92
|
-
const payloadDir = row.PayloadDir || this.parameters?.payloadDir || "payload";
|
|
93
|
-
const filePath = path_1.default.resolve(payloadDir, payloadFile);
|
|
94
|
-
if (!fs_1.default.existsSync(filePath)) {
|
|
95
|
-
throw new Error(`Payload file not found for API request: ${filePath}`);
|
|
96
|
-
}
|
|
97
|
-
const payload = JSON.parse(fs_1.default.readFileSync(filePath, "utf-8"));
|
|
98
|
-
this.log?.(`📞 Making API ${method} request to ${url} with payload from ${payloadFile}`);
|
|
99
|
-
const response = await this.page.request[method.toLowerCase() // Added 'delete' for completeness if needed
|
|
100
|
-
](url, {
|
|
101
|
-
data: payload,
|
|
102
|
-
});
|
|
103
|
-
const responseBody = await response.json();
|
|
104
|
-
this.data.lastApiResponse = responseBody;
|
|
105
|
-
this.data.lastStatusCode = response.status();
|
|
106
|
-
this.log?.(`✅ API response status: ${response.status()}, body: ${JSON.stringify(responseBody).slice(0, 100)}...`);
|
|
107
|
-
if (row.SaveAs) {
|
|
108
|
-
// Using the optional 'SaveAs' column
|
|
109
|
-
this.data[row.SaveAs] = responseBody;
|
|
110
|
-
this.log?.(`💾 API response saved as alias "${row.SaveAs}"`);
|
|
111
|
-
}
|
|
112
|
-
continue; // Move to next row
|
|
113
|
-
}
|
|
114
|
-
// ✅ Local Storage (e.g., `set:localStorage:auth_token`)
|
|
115
|
-
if (target.startsWith("set:localStorage:")) {
|
|
116
|
-
const [, , key] = target.split(":"); // target has "set:localStorage:key"
|
|
117
|
-
if (typeof key !== "string" || !key) {
|
|
118
|
-
throw new Error("Local storage key must be a non-empty string for 'set:localStorage:'.");
|
|
119
|
-
}
|
|
120
|
-
const resolvedValue = (0, resolveUtils_1.resolveLoginValue)(rawValue, this) ?? ""; // RawValue holds the actual data or alias
|
|
121
|
-
await this.page.evaluate(([k, v]) => localStorage.setItem(k, v), [key, resolvedValue]);
|
|
122
|
-
this.log?.(`📦 Set localStorage item "${key}" to "${resolvedValue.slice(0, 50)}..."`);
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// ✅ Session Storage (e.g., `set:sessionStorage:user_id`)
|
|
126
|
-
if (target.startsWith("set:sessionStorage:")) {
|
|
127
|
-
const [, , key] = target.split(":"); // target has "set:sessionStorage:key"
|
|
128
|
-
if (typeof key !== "string" || !key) {
|
|
129
|
-
throw new Error("Session storage key must be a non-empty string for 'set:sessionStorage:'.");
|
|
130
|
-
}
|
|
131
|
-
const resolvedValue = (0, resolveUtils_1.resolveLoginValue)(rawValue, this) ?? ""; // RawValue holds the actual data or alias
|
|
132
|
-
await this.page.evaluate(([k, v]) => sessionStorage.setItem(k, v), [key, resolvedValue]);
|
|
133
|
-
this.log?.(`📦 Set sessionStorage item "${key}" to "${resolvedValue.slice(0, 50)}..."`);
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
// ✅ Wait (e.g., `wait` in Target, `wait:1000` in Value)
|
|
137
|
-
if (target === "wait") {
|
|
138
|
-
const [, timeMs] = rawValue.split(":");
|
|
139
|
-
const waitTime = Number(timeMs);
|
|
140
|
-
if (!isNaN(waitTime)) {
|
|
141
|
-
this.log?.(`⏳ Waiting for ${waitTime}ms...`);
|
|
142
|
-
await this.page.waitForTimeout(waitTime);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
throw new Error(`Invalid wait time specified: "${rawValue}". Expected format "wait:milliseconds".`);
|
|
146
|
-
}
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
// ✅ Reload (e.g., `reload` in Target)
|
|
150
|
-
if (target === "reload") {
|
|
151
|
-
this.log?.("🔄 Reloading page...");
|
|
152
|
-
await this.page.reload();
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
// --- Actions on a specific Locator ---
|
|
156
|
-
const locator = this.getLocator(target); // Get locator for UI interactions/assertions
|
|
157
|
-
// ✅ Assertions (e.g., `.dashboard-header` | `assert:visible`)
|
|
158
|
-
if (rawValue.startsWith("assert:")) {
|
|
159
|
-
const [, type, expected] = rawValue.split(":");
|
|
160
|
-
if (type === "visible") {
|
|
161
|
-
this.log?.(`🔎 Asserting "${target}" is visible.`);
|
|
162
|
-
await (0, test_1.expect)(locator).toBeVisible();
|
|
163
|
-
}
|
|
164
|
-
else if (type === "text") {
|
|
165
|
-
this.log?.(`🔎 Asserting "${target}" has text "${expected}"`);
|
|
166
|
-
await (0, test_1.expect)(locator).toHaveText(expected ?? "", {
|
|
167
|
-
useInnerText: true, // Prefer innerText for visible text content
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
else if (type === "value") {
|
|
171
|
-
this.log?.(`🔎 Asserting "${target}" has value "${expected}"`);
|
|
172
|
-
await (0, test_1.expect)(locator).toHaveValue(expected ?? "");
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
throw new Error(`❌ Unknown assertion type: "${type}" for target "${target}".`);
|
|
176
|
-
}
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
// ✅ Click (e.g., `button:has-text("Sign In")` | `click`)
|
|
180
|
-
if (rawValue === "click") {
|
|
181
|
-
this.log?.(`👆 Clicking on "${target}"`);
|
|
182
|
-
await locator.click();
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
// ✅ Check (e.g., `input[type='checkbox']` | `check`)
|
|
186
|
-
if (rawValue === "check") {
|
|
187
|
-
this.log?.(`☑️ Checking "${target}"`);
|
|
188
|
-
await locator.check();
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
// ✅ Uncheck (e.g., `input[type='checkbox']` | `uncheck`)
|
|
192
|
-
if (rawValue === "uncheck") {
|
|
193
|
-
this.log?.(`🔲 Unchecking "${target}"`);
|
|
194
|
-
await locator.uncheck();
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
// ✅ Select (e.g., `select[name='role']` | `select`)
|
|
198
|
-
if (rawValue === "select") {
|
|
199
|
-
this.log?.(`🔽 Selecting first option for "${target}"`);
|
|
200
|
-
await locator.selectOption({ index: 0 }); // Typically used for dropdowns
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
// ✅ File upload (e.g., `input[type='file']` | `upload:fixtures/profile-pic.jpg`)
|
|
204
|
-
if (rawValue.startsWith("upload:")) {
|
|
205
|
-
const filePath = rawValue.split("upload:")[1].trim();
|
|
206
|
-
const resolvedPath = path_1.default.resolve(filePath);
|
|
207
|
-
if (!fs_1.default.existsSync(resolvedPath)) {
|
|
208
|
-
throw new Error(`File not found for upload: ${filePath} (resolved to: ${resolvedPath})`);
|
|
209
|
-
}
|
|
210
|
-
this.log?.(`📤 Uploading file "${resolvedPath}" to "${target}"`);
|
|
211
|
-
await locator.setInputFiles(resolvedPath);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
// ✅ Drag and drop (e.g., `div.upload-target` | `drag:.upload-preview`)
|
|
215
|
-
if (rawValue.startsWith("drag:")) {
|
|
216
|
-
const targetSelector = rawValue.split("drag:")[1].trim();
|
|
217
|
-
const targetLocator = this.getLocator(targetSelector);
|
|
218
|
-
this.log?.(`🖐️ Dragging "${target}" to "${targetSelector}"`);
|
|
219
|
-
await locator.dragTo(targetLocator);
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
// ✅ Default: fill (if no other action matches, assume fill)
|
|
223
|
-
// Ensure `value` is resolved for normal fill actions
|
|
224
|
-
const fillValue = (0, resolveUtils_1.resolveLoginValue)(rawValue, this);
|
|
225
|
-
if (fillValue !== undefined) {
|
|
226
|
-
this.log?.(`✍️ Filling "${target}" with "${String(fillValue).slice(0, 50)}..."`);
|
|
227
|
-
await locator.fill(String(fillValue));
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
// This case should ideally not be hit if rawValue is always handled,
|
|
231
|
-
// but good for debugging if an unhandled action slips through.
|
|
232
|
-
this.log?.(`⚠️ No action performed for target "${target}" with value "${rawValue}"`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// Register the Cucumber step
|
|
237
|
-
(0, cucumber_1.When)("I fill the following {string} form data:", When_I_fill_the_following_form_data);
|
package/lib/actions/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./clickSteps";
|
|
2
|
-
export * from "./cookieSteps";
|
|
3
|
-
export * from "./debugSteps";
|
|
4
|
-
export * from "./elementFindSteps";
|
|
5
|
-
export * from "./fillFormSteps";
|
|
6
|
-
export * from "./inputSteps";
|
|
7
|
-
export * from "./interceptionSteps";
|
|
8
|
-
export * from "./miscSteps";
|
|
9
|
-
export * from "./mouseSteps";
|
|
10
|
-
export * from "./scrollSteps";
|
|
11
|
-
export * from "./storageSteps";
|
package/lib/actions/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// Actions
|
|
18
|
-
__exportStar(require("./clickSteps"), exports);
|
|
19
|
-
__exportStar(require("./cookieSteps"), exports);
|
|
20
|
-
__exportStar(require("./debugSteps"), exports);
|
|
21
|
-
__exportStar(require("./elementFindSteps"), exports);
|
|
22
|
-
__exportStar(require("./fillFormSteps"), exports);
|
|
23
|
-
__exportStar(require("./inputSteps"), exports);
|
|
24
|
-
__exportStar(require("./interceptionSteps"), exports);
|
|
25
|
-
__exportStar(require("./miscSteps"), exports);
|
|
26
|
-
__exportStar(require("./mouseSteps"), exports);
|
|
27
|
-
__exportStar(require("./scrollSteps"), exports);
|
|
28
|
-
__exportStar(require("./storageSteps"), exports);
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { CustomWorld } from "../helpers/world";
|
|
2
|
-
/**
|
|
3
|
-
* Checks the previously selected element (e.g., a checkbox or radio button).
|
|
4
|
-
*
|
|
5
|
-
* ```gherkin
|
|
6
|
-
* When I check
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* When I find element by label text "Remember me"
|
|
11
|
-
* And I check
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
15
|
-
* to a checkbox or radio button. It will mark the element as checked. Optional Playwright
|
|
16
|
-
* `CheckOptions` can be provided via a data table.
|
|
17
|
-
*/
|
|
18
|
-
export declare function When_I_check(this: CustomWorld, ...rest: any[]): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Unchecks the previously selected element (e.g., a checkbox).
|
|
21
|
-
*
|
|
22
|
-
* ```gherkin
|
|
23
|
-
* When I uncheck
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* When I find element by label text "Agree to terms"
|
|
28
|
-
* And I uncheck
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
32
|
-
* to a checkbox. It will mark the element as unchecked. Optional Playwright
|
|
33
|
-
* `CheckOptions` can be provided via a data table.
|
|
34
|
-
*/
|
|
35
|
-
export declare function When_I_uncheck(this: CustomWorld, ...rest: any[]): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Checks a specific input element, requiring a preceding step to select it.
|
|
38
|
-
*
|
|
39
|
-
* ```gherkin
|
|
40
|
-
* When I check input
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* When I find element by selector "input#myCheckbox"
|
|
45
|
-
* And I check input
|
|
46
|
-
*
|
|
47
|
-
* @remarks
|
|
48
|
-
* This is an alias for "I check". It requires a preceding step that sets the
|
|
49
|
-
* {@link CustomWorld.element | current element} to an input element (like a checkbox or radio).
|
|
50
|
-
* Optional Playwright `CheckOptions` can be provided via a data table.
|
|
51
|
-
*/
|
|
52
|
-
export declare function When_I_check_input(this: CustomWorld, ...rest: any[]): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Unchecks a specific input element, requiring a preceding step to select it.
|
|
55
|
-
*
|
|
56
|
-
* ```gherkin
|
|
57
|
-
* When I uncheck input
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* When I find element by selector "input#newsletter"
|
|
62
|
-
* And I uncheck input
|
|
63
|
-
*
|
|
64
|
-
* @remarks
|
|
65
|
-
* This is an alias for "I uncheck". It requires a preceding step that sets the
|
|
66
|
-
* {@link CustomWorld.element | current element} to an input element (like a checkbox).
|
|
67
|
-
* Optional Playwright `CheckOptions` can be provided via a data table.
|
|
68
|
-
*/
|
|
69
|
-
export declare function When_I_uncheck_input(this: CustomWorld, ...rest: any[]): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Types the given text into the previously selected element.
|
|
72
|
-
*
|
|
73
|
-
* ```gherkin
|
|
74
|
-
* When I type {string}
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* When I find element by selector "input[name='email']"
|
|
79
|
-
* And I type "user@example.com"
|
|
80
|
-
*
|
|
81
|
-
* @remarks
|
|
82
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
83
|
-
* to an input field (or any element that supports `fill`). The provided text can be a literal
|
|
84
|
-
* string or a faker expression (e.g., `{{internet.email}}`).
|
|
85
|
-
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
86
|
-
*/
|
|
87
|
-
export declare const When_I_type: (this: CustomWorld, textOrAlias: string, ...rest: any[]) => Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Types the value stored in an alias into the previously selected element.
|
|
90
|
-
*
|
|
91
|
-
* ```gherkin
|
|
92
|
-
* When I type stored {string}
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* Given I store "my.user@example.com" as "userEmail"
|
|
97
|
-
* When I find element by selector "input[name='email']"
|
|
98
|
-
* And I type stored "userEmail"
|
|
99
|
-
*
|
|
100
|
-
* @remarks
|
|
101
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
102
|
-
* to an input field. The `string` argument must be an alias (e.g., `userEmail`).
|
|
103
|
-
* The value associated with this alias in `this.data` will be typed into the element.
|
|
104
|
-
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
105
|
-
*/
|
|
106
|
-
export declare const When_I_type_stored: (this: CustomWorld, textOrAlias: string, ...rest: any[]) => Promise<void>;
|
|
107
|
-
/**
|
|
108
|
-
* Types a randomly generated value (using Faker.js) into the previously selected element.
|
|
109
|
-
*
|
|
110
|
-
* ```gherkin
|
|
111
|
-
* When I type random {string}
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* When I find element by selector "input[name='username']"
|
|
116
|
-
* And I type random "internet.userName"
|
|
117
|
-
*
|
|
118
|
-
* @remarks
|
|
119
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
120
|
-
* to an input field. The `string` argument should be a Faker.js path (e.g., `internet.email`,
|
|
121
|
-
* `person.firstName`). A random value generated by Faker will be typed into the element.
|
|
122
|
-
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
123
|
-
*/
|
|
124
|
-
export declare const When_I_type_random: (this: CustomWorld, textOrAlias: string, ...rest: any[]) => Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Sets the value of the previously selected element.
|
|
127
|
-
*
|
|
128
|
-
* ```gherkin
|
|
129
|
-
* When I set value {string}
|
|
130
|
-
* ```
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* When I find element by selector "input[name='password']"
|
|
134
|
-
* And I set value "@userPassword"
|
|
135
|
-
*
|
|
136
|
-
* @remarks
|
|
137
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
138
|
-
* to an input field (or any element that supports `fill`). The provided `valueOrAlias` can be
|
|
139
|
-
* a literal string, an alias (prefixed with `@`), or a Faker expression. This will directly
|
|
140
|
-
* set the input's value, which is generally faster than typing for non-interactive scenarios.
|
|
141
|
-
* Optional Playwright `FillOptions` can be provided via a data table.
|
|
142
|
-
*/
|
|
143
|
-
export declare function When_I_set_value(this: CustomWorld, valueOrAlias: string, ...rest: any[]): Promise<void>;
|
|
144
|
-
/**
|
|
145
|
-
* Clears the value of the previously selected element.
|
|
146
|
-
*
|
|
147
|
-
* ```gherkin
|
|
148
|
-
* When I clear
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* When I find element by selector "input[name='search']"
|
|
153
|
-
* And I clear
|
|
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`). It effectively empties the input field.
|
|
158
|
-
*/
|
|
159
|
-
export declare function When_I_clear(this: CustomWorld): Promise<void>;
|
|
160
|
-
/**
|
|
161
|
-
* Submits the form associated with the previously selected element, or the first form on the page.
|
|
162
|
-
*
|
|
163
|
-
* ```gherkin
|
|
164
|
-
* When I submit
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* When I find element by selector "form#loginForm"
|
|
169
|
-
* And I submit
|
|
170
|
-
* # OR (submits the first form found if no element is selected)
|
|
171
|
-
* When I go to "/login"
|
|
172
|
-
* And I submit
|
|
173
|
-
*
|
|
174
|
-
* @remarks
|
|
175
|
-
* This step will find a form to submit. If {@link CustomWorld.element | this.element}
|
|
176
|
-
* is a form or an element within a form, that form will be submitted. Otherwise, it will
|
|
177
|
-
* attempt to submit the first `<form>` element found on the page.
|
|
178
|
-
* It uses a direct DOM `submit()` call, which bypasses Playwright's default event handling
|
|
179
|
-
* and can be useful for testing native form submission behavior.
|
|
180
|
-
*/
|
|
181
|
-
export declare function When_I_submit(this: CustomWorld): Promise<void>;
|
|
182
|
-
/**
|
|
183
|
-
* Selects an option by its visible text label in a `<select>` element.
|
|
184
|
-
*
|
|
185
|
-
* ```gherkin
|
|
186
|
-
* When I select option {string}
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* When I find element by selector "select[name='role']"
|
|
191
|
-
* And I select option "Administrator"
|
|
192
|
-
*
|
|
193
|
-
* @remarks
|
|
194
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
195
|
-
* to a `<select>` HTML element. It will then select the option whose visible text matches
|
|
196
|
-
* the provided `option` string.
|
|
197
|
-
* Optional Playwright `SelectOptionOptions` can be provided via a data table.
|
|
198
|
-
*/
|
|
199
|
-
export declare function When_I_select_option(this: CustomWorld, option: string, ...rest: any[]): Promise<void>;
|
|
200
|
-
/**
|
|
201
|
-
* Sets the file input of the previously selected element to the specified file path.
|
|
202
|
-
*
|
|
203
|
-
* ```gherkin
|
|
204
|
-
* When I select file {string}
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* When I find element by selector "input[type='file']"
|
|
209
|
-
* And I select file "path/to/my/document.pdf"
|
|
210
|
-
*
|
|
211
|
-
* @remarks
|
|
212
|
-
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
213
|
-
* to an `input` element of `type="file"`. The `filePath` should be relative to your project's
|
|
214
|
-
* root or an absolute path. Playwright will automatically handle making the file available
|
|
215
|
-
* for upload.
|
|
216
|
-
* Optional Playwright `SetInputFilesOptions` can be provided via a data table.
|
|
217
|
-
*/
|
|
218
|
-
export declare function When_I_select_file(this: CustomWorld, filePath: string, ...rest: any[]): Promise<void>;
|