playwright-cucumber-ts-steps 0.0.9 โ 0.1.0
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/dist/actions/clickSteps.js +32 -49
- package/dist/actions/elementFindSteps.js +25 -46
- package/dist/actions/inputSteps.js +33 -40
- package/dist/actions/miscSteps.js +11 -21
- package/dist/actions/mouseSteps.js +3 -6
- package/dist/actions/storageSteps.js +1 -2
- package/dist/assertions/buttonAndTextVisibilitySteps.js +4 -8
- package/dist/assertions/elementSteps.js +4 -6
- package/dist/assertions/interceptionRequestsSteps.js +14 -6
- package/dist/assertions/storageSteps.js +2 -3
- package/dist/assertions/visualSteps.js +5 -8
- package/dist/custom_setups/loginHooks.js +5 -8
- package/dist/helpers/hooks.js +5 -7
- package/dist/helpers/world.js +7 -9
- package/package.json +17 -1
- package/dist/assertions/InterceptionRequests.d.ts +0 -1
- package/dist/assertions/InterceptionRequests.js +0 -191
- package/dist/assertions/button_and_text_visibility.d.ts +0 -1
- package/dist/assertions/button_and_text_visibility.js +0 -172
- package/dist/custom_setups/global-login.d.ts +0 -2
- package/dist/custom_setups/global-login.js +0 -20
|
@@ -2,45 +2,40 @@
|
|
|
2
2
|
import { When } from "@cucumber/cucumber";
|
|
3
3
|
import { parseClickOptions } from "../helpers/utils/optionsUtils";
|
|
4
4
|
When("I click", async function (...rest) {
|
|
5
|
-
var _a;
|
|
6
5
|
const maybeTable = rest[0];
|
|
7
|
-
const options =
|
|
6
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
8
7
|
if (!this.element)
|
|
9
8
|
throw new Error("โ No stored element to click.");
|
|
10
9
|
await this.element.click(options);
|
|
11
|
-
|
|
10
|
+
this.log?.("๐ฑ๏ธ Clicked on stored element");
|
|
12
11
|
});
|
|
13
12
|
When("I click on button {string}", async function (label, ...rest) {
|
|
14
|
-
var _a;
|
|
15
13
|
const maybeTable = rest[0];
|
|
16
|
-
const options =
|
|
14
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
17
15
|
const button = await this.page.getByRole("button", { name: label });
|
|
18
16
|
await button.click(options);
|
|
19
17
|
this.element = button;
|
|
20
|
-
|
|
18
|
+
this.log?.(`๐ฑ๏ธ Clicked on button "${label}"`);
|
|
21
19
|
});
|
|
22
20
|
When("I click on link {string}", async function (text, ...rest) {
|
|
23
|
-
var _a;
|
|
24
21
|
const maybeTable = rest[0];
|
|
25
|
-
const options =
|
|
22
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
26
23
|
const link = await this.page.getByRole("link", { name: text });
|
|
27
24
|
await link.click(options);
|
|
28
25
|
this.element = link;
|
|
29
|
-
|
|
26
|
+
this.log?.(`โ
Clicked on link "${text}"`);
|
|
30
27
|
});
|
|
31
28
|
When("I click on label {string}", async function (labelText, ...rest) {
|
|
32
|
-
var _a;
|
|
33
29
|
const maybeTable = rest[0];
|
|
34
|
-
const options =
|
|
30
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
35
31
|
const label = await this.page.getByLabel(labelText);
|
|
36
32
|
await label.click(options);
|
|
37
33
|
this.element = label;
|
|
38
|
-
|
|
34
|
+
this.log?.(`๐ท๏ธ Clicked on label "${labelText}"`);
|
|
39
35
|
});
|
|
40
36
|
When("I click on text {string}", async function (rawText, ...rest) {
|
|
41
|
-
var _a;
|
|
42
37
|
const maybeTable = rest[0];
|
|
43
|
-
const options =
|
|
38
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
44
39
|
let text = rawText;
|
|
45
40
|
if (rawText.startsWith("@")) {
|
|
46
41
|
const alias = rawText.slice(1);
|
|
@@ -52,22 +47,20 @@ When("I click on text {string}", async function (rawText, ...rest) {
|
|
|
52
47
|
await locator.first().waitFor({ state: "visible", timeout: 5000 });
|
|
53
48
|
await locator.first().click(options);
|
|
54
49
|
this.element = locator.first();
|
|
55
|
-
|
|
50
|
+
this.log?.(`๐ฑ๏ธ Clicked on text "${text}"`);
|
|
56
51
|
});
|
|
57
52
|
When("I click on exact text {string}", async function (exactText, ...rest) {
|
|
58
|
-
var _a;
|
|
59
53
|
const maybeTable = rest[0];
|
|
60
|
-
const options =
|
|
54
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
61
55
|
const locator = this.page.getByText(exactText, { exact: true });
|
|
62
56
|
await locator.waitFor({ state: "visible", timeout: 5000 });
|
|
63
57
|
await locator.click(options);
|
|
64
58
|
this.element = locator;
|
|
65
|
-
|
|
59
|
+
this.log?.(`๐ฑ๏ธ Clicked on exact text "${exactText}"`);
|
|
66
60
|
});
|
|
67
61
|
When("I click all", async function (...rest) {
|
|
68
|
-
var _a, _b;
|
|
69
62
|
const maybeTable = rest[0];
|
|
70
|
-
const options =
|
|
63
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
71
64
|
if (!this.elements)
|
|
72
65
|
throw new Error("โ No stored elements to click.");
|
|
73
66
|
const count = await this.elements.count();
|
|
@@ -77,77 +70,68 @@ When("I click all", async function (...rest) {
|
|
|
77
70
|
const el = this.elements.nth(i);
|
|
78
71
|
await el.waitFor({ state: "visible", timeout: 5000 });
|
|
79
72
|
await el.click(options);
|
|
80
|
-
|
|
73
|
+
this.log?.(`๐ฑ๏ธ Clicked element #${i + 1}`);
|
|
81
74
|
}
|
|
82
|
-
|
|
75
|
+
this.log?.(`โ
Clicked all ${count} elements.`);
|
|
83
76
|
});
|
|
84
77
|
When("I double click on text {string}", async function (text, ...rest) {
|
|
85
|
-
var _a;
|
|
86
78
|
const maybeTable = rest[0];
|
|
87
|
-
const options =
|
|
79
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
88
80
|
const element = this.element || this.page.getByText(text);
|
|
89
81
|
await element.dblclick(options);
|
|
90
|
-
|
|
82
|
+
this.log?.(`๐ฑ๏ธ Double-clicked on text "${text}"`);
|
|
91
83
|
});
|
|
92
84
|
When("I double click position {int} {int}", async function (x, y, ...rest) {
|
|
93
|
-
var _a;
|
|
94
85
|
const maybeTable = rest[0];
|
|
95
|
-
const options =
|
|
86
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
96
87
|
await this.page.mouse.dblclick(x, y, options);
|
|
97
|
-
|
|
88
|
+
this.log?.(`๐ฑ๏ธ Double-clicked at (${x}, ${y})`);
|
|
98
89
|
});
|
|
99
90
|
When("I double click", async function (...rest) {
|
|
100
|
-
var _a;
|
|
101
91
|
const maybeTable = rest[0];
|
|
102
|
-
const options =
|
|
92
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
103
93
|
if (!this.element)
|
|
104
94
|
throw new Error("โ No stored element to double-click.");
|
|
105
95
|
await this.element.dblclick(options);
|
|
106
|
-
|
|
96
|
+
this.log?.("๐ฑ๏ธ Double-clicked on stored element");
|
|
107
97
|
});
|
|
108
98
|
When("I right click", async function (...rest) {
|
|
109
|
-
var _a;
|
|
110
99
|
const maybeTable = rest[0];
|
|
111
|
-
const options =
|
|
100
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
112
101
|
if (!this.element)
|
|
113
102
|
throw new Error("โ No stored element to right-click.");
|
|
114
103
|
await this.element.click({ button: "right", ...options });
|
|
115
|
-
|
|
104
|
+
this.log?.("๐ฑ๏ธ Right-clicked on stored element");
|
|
116
105
|
});
|
|
117
106
|
When("I right click on text {string}", async function (text, ...rest) {
|
|
118
|
-
var _a;
|
|
119
107
|
const maybeTable = rest[0];
|
|
120
|
-
const options =
|
|
108
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
121
109
|
const element = this.page.getByText(text);
|
|
122
110
|
await element.click({ button: "right", ...options });
|
|
123
|
-
|
|
111
|
+
this.log?.(`๐ฑ๏ธ Right-clicked on text "${text}"`);
|
|
124
112
|
});
|
|
125
113
|
When("I right click position {int} {int}", async function (x, y, ...rest) {
|
|
126
|
-
var _a;
|
|
127
114
|
const maybeTable = rest[0];
|
|
128
|
-
const options =
|
|
115
|
+
const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
|
|
129
116
|
await this.page.mouse.click(x, y, { button: "right", ...options });
|
|
130
|
-
|
|
117
|
+
this.log?.(`๐ฑ๏ธ Right-clicked at (${x}, ${y})`);
|
|
131
118
|
});
|
|
132
119
|
When("I blur", async function () {
|
|
133
|
-
var _a;
|
|
134
120
|
await this.page.evaluate(() => {
|
|
135
121
|
const active = document.activeElement;
|
|
136
122
|
if (active && typeof active.blur === "function") {
|
|
137
123
|
active.blur();
|
|
138
124
|
}
|
|
139
125
|
});
|
|
140
|
-
|
|
126
|
+
this.log?.("๐ Blurred active element");
|
|
141
127
|
});
|
|
142
128
|
When("I focus", async function () {
|
|
143
|
-
var _a;
|
|
144
129
|
if (!this.element)
|
|
145
130
|
throw new Error("โ No stored element to focus.");
|
|
146
131
|
await this.element.focus();
|
|
147
|
-
|
|
132
|
+
this.log?.("๐ฏ Focused stored element");
|
|
148
133
|
});
|
|
149
134
|
When("I click all", async function (dataTable) {
|
|
150
|
-
var _a, _b;
|
|
151
135
|
const options = parseClickOptions(dataTable);
|
|
152
136
|
if (!this.elements) {
|
|
153
137
|
throw new Error("โ No elements stored. Use a 'find' step before 'I click all'.");
|
|
@@ -160,14 +144,13 @@ When("I click all", async function (dataTable) {
|
|
|
160
144
|
const element = this.elements.nth(i);
|
|
161
145
|
await element.waitFor({ state: "visible", timeout: 5000 });
|
|
162
146
|
await element.click(options);
|
|
163
|
-
|
|
147
|
+
this.log?.(`๐ฑ๏ธ Clicked element #${i + 1}`);
|
|
164
148
|
}
|
|
165
|
-
|
|
149
|
+
this.log?.(`โ
Clicked all ${count} stored elements.`);
|
|
166
150
|
});
|
|
167
151
|
When(/^I click on selector "([^"]+)"$/, async function (selector) {
|
|
168
|
-
var _a;
|
|
169
152
|
const scope = this.getScope();
|
|
170
153
|
const element = scope.locator(selector);
|
|
171
154
|
await element.click();
|
|
172
|
-
|
|
155
|
+
this.log?.(`๐ฑ๏ธ Clicked on selector: ${selector}`);
|
|
173
156
|
});
|
|
@@ -8,10 +8,9 @@ When("I find element by selector {string}", async function (selector) {
|
|
|
8
8
|
await expect(this.element).toHaveCount(1);
|
|
9
9
|
});
|
|
10
10
|
When("I find elements by selector {string}", async function (selector) {
|
|
11
|
-
var _a;
|
|
12
11
|
this.elements = this.page.locator(selector);
|
|
13
12
|
const count = await this.elements.count();
|
|
14
|
-
|
|
13
|
+
this.log?.(`Found ${count} elements with selector ${selector}`);
|
|
15
14
|
});
|
|
16
15
|
When("I find element by text {string}", async function (text) {
|
|
17
16
|
this.element = this.page.getByText(text, { exact: true });
|
|
@@ -46,11 +45,10 @@ When("I find element by name {string}", async function (name) {
|
|
|
46
45
|
await expect(this.element).toHaveCount(1);
|
|
47
46
|
});
|
|
48
47
|
When("I find buttons by text {string}", async function (buttonText) {
|
|
49
|
-
var _a, _b;
|
|
50
48
|
// ๐ง Resolve alias
|
|
51
49
|
if (buttonText.startsWith("@")) {
|
|
52
50
|
const alias = buttonText.slice(1);
|
|
53
|
-
buttonText =
|
|
51
|
+
buttonText = this.data?.[alias];
|
|
54
52
|
if (!buttonText) {
|
|
55
53
|
throw new Error(`No value found for alias "@${alias}"`);
|
|
56
54
|
}
|
|
@@ -60,7 +58,7 @@ When("I find buttons by text {string}", async function (buttonText) {
|
|
|
60
58
|
name: buttonText,
|
|
61
59
|
exact: false,
|
|
62
60
|
});
|
|
63
|
-
|
|
61
|
+
this.log?.(`๐ Stored all buttons matching text "${buttonText}"`);
|
|
64
62
|
});
|
|
65
63
|
// =============================
|
|
66
64
|
// WHEN I GET ELEMENT(S)
|
|
@@ -82,7 +80,6 @@ When("I get last element", async function () {
|
|
|
82
80
|
this.element = this.elements.last();
|
|
83
81
|
});
|
|
84
82
|
When(/^I get (\d+)(?:st|nd|rd|th) element$/, async function (index) {
|
|
85
|
-
var _a;
|
|
86
83
|
if (!this.elements)
|
|
87
84
|
throw new Error("No elements stored to pick from");
|
|
88
85
|
const count = await this.elements.count();
|
|
@@ -90,17 +87,16 @@ When(/^I get (\d+)(?:st|nd|rd|th) element$/, async function (index) {
|
|
|
90
87
|
throw new Error(`Cannot get element ${index} โ only ${count} found`);
|
|
91
88
|
}
|
|
92
89
|
this.element = this.elements.nth(index - 1);
|
|
93
|
-
|
|
90
|
+
this.log?.(`Selected ${index} element from stored elements`);
|
|
94
91
|
});
|
|
95
92
|
When("I find elements by role {string}", async function (role) {
|
|
96
|
-
var _a;
|
|
97
93
|
const locator = this.page.getByRole(role);
|
|
98
94
|
const count = await locator.count();
|
|
99
95
|
if (count === 0) {
|
|
100
96
|
throw new Error(`No elements found with role "${role}"`);
|
|
101
97
|
}
|
|
102
98
|
this.elements = locator;
|
|
103
|
-
|
|
99
|
+
this.log?.(`Stored ${count} elements with role "${role}"`);
|
|
104
100
|
});
|
|
105
101
|
// When(
|
|
106
102
|
// "I get {int}{ordinal} element",
|
|
@@ -129,104 +125,87 @@ When("I get focused element", async function () {
|
|
|
129
125
|
this.element = (await this.page.evaluateHandle(() => document.activeElement));
|
|
130
126
|
});
|
|
131
127
|
When("I store element text as {string}", async function (alias) {
|
|
132
|
-
var _a;
|
|
133
128
|
const element = this.element;
|
|
134
129
|
if (!element)
|
|
135
130
|
throw new Error("No element selected");
|
|
136
131
|
const text = await element.textContent();
|
|
137
|
-
this.data[alias] = text
|
|
138
|
-
|
|
132
|
+
this.data[alias] = text?.trim();
|
|
133
|
+
this.log?.(`Stored text "${text}" as "${alias}"`);
|
|
139
134
|
});
|
|
140
135
|
When("I find textarea by label text {string}", async function (label) {
|
|
141
|
-
var _a;
|
|
142
136
|
this.element = this.page.getByLabel(label);
|
|
143
|
-
|
|
137
|
+
this.log?.(`Stored textarea with label "${label}"`);
|
|
144
138
|
});
|
|
145
139
|
When("I find textarea by placeholder text {string}", async function (placeholder) {
|
|
146
|
-
var _a;
|
|
147
140
|
this.element = this.page.getByPlaceholder(placeholder);
|
|
148
|
-
|
|
141
|
+
this.log?.(`Stored textarea with placeholder "${placeholder}"`);
|
|
149
142
|
});
|
|
150
143
|
When("I find textareas by label text {string}", async function (label) {
|
|
151
|
-
var _a;
|
|
152
144
|
this.elements = this.page.locator(`label:has-text("${label}") + textarea`);
|
|
153
|
-
|
|
145
|
+
this.log?.(`Stored multiple textareas with label "${label}"`);
|
|
154
146
|
});
|
|
155
147
|
When("I find textarea by name {string}", async function (name) {
|
|
156
|
-
var _a;
|
|
157
148
|
this.element = this.page.locator(`textarea[name="${name}"]`);
|
|
158
|
-
|
|
149
|
+
this.log?.(`Stored textarea with name "${name}"`);
|
|
159
150
|
});
|
|
160
151
|
When("I find textareas by ID {string}", async function (id) {
|
|
161
|
-
var _a;
|
|
162
152
|
this.elements = this.page.locator(`textarea#${id}`);
|
|
163
|
-
|
|
153
|
+
this.log?.(`Stored multiple textareas with ID "${id}"`);
|
|
164
154
|
});
|
|
165
155
|
When("I find input by ID {string}", async function (id) {
|
|
166
|
-
var _a;
|
|
167
156
|
this.element = this.page.locator(`input#${id}`);
|
|
168
|
-
|
|
157
|
+
this.log?.(`Stored input with ID "${id}"`);
|
|
169
158
|
});
|
|
170
159
|
When("I find inputs by ID {string}", async function (id) {
|
|
171
|
-
var _a;
|
|
172
160
|
this.elements = this.page.locator(`input#${id}`);
|
|
173
|
-
|
|
161
|
+
this.log?.(`Stored multiple inputs with ID "${id}"`);
|
|
174
162
|
});
|
|
175
163
|
When("I find textareas by placeholder text {string}", async function (placeholder) {
|
|
176
|
-
var _a;
|
|
177
164
|
this.elements = this.page.locator(`textarea[placeholder="${placeholder}"]`);
|
|
178
|
-
|
|
165
|
+
this.log?.(`Stored multiple textareas with placeholder "${placeholder}"`);
|
|
179
166
|
});
|
|
180
167
|
When("I find input by label text {string}", async function (label) {
|
|
181
|
-
var _a;
|
|
182
168
|
this.element = this.page.getByLabel(label);
|
|
183
|
-
|
|
169
|
+
this.log?.(`Stored input with label "${label}"`);
|
|
184
170
|
});
|
|
185
171
|
When("I find input by name {string}", async function (name) {
|
|
186
|
-
var _a;
|
|
187
172
|
this.element = this.page.locator(`input[name="${name}"]`);
|
|
188
|
-
|
|
173
|
+
this.log?.(`Stored input with name "${name}"`);
|
|
189
174
|
});
|
|
190
175
|
When("I find input by placeholder text {string}", async function (placeholder) {
|
|
191
|
-
var _a;
|
|
192
176
|
this.element = this.page.getByPlaceholder(placeholder);
|
|
193
|
-
|
|
177
|
+
this.log?.(`Stored input with placeholder "${placeholder}"`);
|
|
194
178
|
});
|
|
195
179
|
When("I find inputs by name {string}", async function (name) {
|
|
196
|
-
var _a;
|
|
197
180
|
this.elements = this.page.locator(`input[name="${name}"]`);
|
|
198
|
-
|
|
181
|
+
this.log?.(`Stored multiple inputs with name "${name}"`);
|
|
199
182
|
});
|
|
200
183
|
When("I find inputs by placeholder text {string}", async function (placeholder) {
|
|
201
|
-
var _a;
|
|
202
184
|
this.elements = this.page.locator(`input[placeholder="${placeholder}"]`);
|
|
203
|
-
|
|
185
|
+
this.log?.(`Stored multiple inputs with placeholder "${placeholder}"`);
|
|
204
186
|
});
|
|
205
187
|
When("I find inputs by label text {string}", async function (label) {
|
|
206
|
-
var _a;
|
|
207
188
|
this.elements = this.page.locator(`label:has-text("${label}") + input`);
|
|
208
|
-
|
|
189
|
+
this.log?.(`Stored multiple inputs with label "${label}"`);
|
|
209
190
|
});
|
|
210
191
|
When("I find inputs by display value {string}", async function (value) {
|
|
211
|
-
var _a, _b;
|
|
212
192
|
// ๐ง Handle alias
|
|
213
193
|
if (value.startsWith("@")) {
|
|
214
194
|
const alias = value.slice(1);
|
|
215
|
-
value =
|
|
195
|
+
value = this.data?.[alias];
|
|
216
196
|
if (!value) {
|
|
217
197
|
throw new Error(`No value found for alias "@${alias}"`);
|
|
218
198
|
}
|
|
219
199
|
}
|
|
220
200
|
// ๐ Find all matching inputs
|
|
221
201
|
this.elements = this.page.locator(`input[value="${value}"]`);
|
|
222
|
-
|
|
202
|
+
this.log?.(`๐ฆ Stored multiple inputs with display value "${value}"`);
|
|
223
203
|
});
|
|
224
204
|
When("I find input by display value {string}", async function (value) {
|
|
225
|
-
var _a, _b;
|
|
226
205
|
// ๐ง Handle alias
|
|
227
206
|
if (value.startsWith("@")) {
|
|
228
207
|
const alias = value.slice(1);
|
|
229
|
-
value =
|
|
208
|
+
value = this.data?.[alias];
|
|
230
209
|
if (!value) {
|
|
231
210
|
throw new Error(`No value found for alias "@${alias}"`);
|
|
232
211
|
}
|
|
@@ -235,5 +214,5 @@ When("I find input by display value {string}", async function (value) {
|
|
|
235
214
|
const locator = this.page.locator(`input[value="${value}"]`);
|
|
236
215
|
await expect(locator).toBeVisible({ timeout: 5000 });
|
|
237
216
|
this.element = locator;
|
|
238
|
-
|
|
217
|
+
this.log?.(`๐ Found input with value: "${value}"`);
|
|
239
218
|
});
|
|
@@ -6,37 +6,34 @@ import fs from "fs";
|
|
|
6
6
|
import { evaluateFaker } from "../helpers/utils/fakerUtils";
|
|
7
7
|
import { parseClickOptions, parseCheckOptions, parseFillOptions, parseSelectOptions, } from "../helpers/utils/optionsUtils";
|
|
8
8
|
When("I check", async function (...rest) {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
const maybeTable = rest[0];
|
|
11
|
-
const options =
|
|
12
|
-
await
|
|
13
|
-
|
|
10
|
+
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
11
|
+
await this.element?.check(options);
|
|
12
|
+
this.log?.("โ
Checked stored checkbox");
|
|
14
13
|
});
|
|
15
14
|
When("I uncheck", async function (...rest) {
|
|
16
|
-
var _a, _b;
|
|
17
15
|
const maybeTable = rest[0];
|
|
18
|
-
const options =
|
|
19
|
-
await
|
|
20
|
-
|
|
16
|
+
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
17
|
+
await this.element?.uncheck(options);
|
|
18
|
+
this.log?.("โ
Unchecked stored checkbox");
|
|
21
19
|
});
|
|
22
20
|
When("I check input", async function (...rest) {
|
|
23
21
|
const maybeTable = rest[0];
|
|
24
|
-
const options =
|
|
22
|
+
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
25
23
|
if (!this.element)
|
|
26
24
|
throw new Error("No input selected");
|
|
27
25
|
await this.element.check(options);
|
|
28
26
|
});
|
|
29
27
|
When("I uncheck input", async function (...rest) {
|
|
30
28
|
const maybeTable = rest[0];
|
|
31
|
-
const options =
|
|
29
|
+
const options = maybeTable?.rowsHash ? parseCheckOptions(maybeTable) : {};
|
|
32
30
|
if (!this.element)
|
|
33
31
|
throw new Error("No input selected");
|
|
34
32
|
await this.element.uncheck(options);
|
|
35
33
|
});
|
|
36
34
|
When("I fill the following {string} form data:", async function (_formName, tableData, ...rest) {
|
|
37
|
-
var _a, _b, _c, _d;
|
|
38
35
|
const maybeOptionsTable = rest[0];
|
|
39
|
-
const globalOptions =
|
|
36
|
+
const globalOptions = maybeOptionsTable?.rowsHash
|
|
40
37
|
? parseClickOptions(maybeOptionsTable)
|
|
41
38
|
: {};
|
|
42
39
|
const rows = tableData.raw().slice(1); // Remove header row
|
|
@@ -67,100 +64,96 @@ When("I fill the following {string} form data:", async function (_formName, tabl
|
|
|
67
64
|
}
|
|
68
65
|
if (resolvedValue === "Click") {
|
|
69
66
|
await element.click(globalOptions);
|
|
70
|
-
|
|
67
|
+
this.log?.(`๐ฑ๏ธ Clicked on "${rawTarget}"`);
|
|
71
68
|
}
|
|
72
69
|
else if (rawTarget.includes('input[type="file"]')) {
|
|
73
70
|
const filePath = path.resolve("test-data", resolvedValue);
|
|
74
71
|
if (!fs.existsSync(filePath))
|
|
75
72
|
throw new Error(`File not found: ${filePath}`);
|
|
76
73
|
await element.setInputFiles(filePath);
|
|
77
|
-
|
|
74
|
+
this.log?.(`๐ Uploaded file to "${rawTarget}": ${resolvedValue}`);
|
|
78
75
|
}
|
|
79
76
|
else {
|
|
80
77
|
const keyPattern = /{(\w+)}/g;
|
|
81
78
|
const matches = [...resolvedValue.matchAll(keyPattern)];
|
|
82
79
|
const keys = matches.map((m) => m[1]);
|
|
83
80
|
const inputText = resolvedValue.replace(keyPattern, "").trim();
|
|
84
|
-
const fillOptions =
|
|
81
|
+
const fillOptions = maybeOptionsTable?.rowsHash
|
|
85
82
|
? parseFillOptions(maybeOptionsTable)
|
|
86
83
|
: {};
|
|
87
84
|
if (inputText) {
|
|
88
85
|
await element.fill(inputText, fillOptions);
|
|
89
|
-
|
|
86
|
+
this.log?.(`โจ๏ธ Filled "${rawTarget}" with: ${inputText}`);
|
|
90
87
|
}
|
|
91
88
|
for (const key of keys) {
|
|
92
89
|
await element.focus();
|
|
93
90
|
await this.page.waitForTimeout(200);
|
|
94
91
|
await element.press(key);
|
|
95
|
-
|
|
92
|
+
this.log?.(`๐น Pressed {${key}} on "${rawTarget}"`);
|
|
96
93
|
}
|
|
97
94
|
}
|
|
98
95
|
await expect(element).toBeVisible();
|
|
99
96
|
}
|
|
100
97
|
});
|
|
101
98
|
const typeStep = async function (textOrAlias, ...rest) {
|
|
102
|
-
var _a, _b;
|
|
103
99
|
if (!this.element)
|
|
104
100
|
throw new Error("No element selected");
|
|
105
101
|
const maybeTable = rest[0];
|
|
106
|
-
const options =
|
|
102
|
+
const options = maybeTable?.rowsHash ? parseFillOptions(maybeTable) : {};
|
|
107
103
|
const text = textOrAlias.startsWith("@")
|
|
108
|
-
?
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
? this.data[textOrAlias.slice(1)] ??
|
|
105
|
+
(() => {
|
|
106
|
+
throw new Error(`No value found for alias "${textOrAlias}"`);
|
|
107
|
+
})()
|
|
111
108
|
: evaluateFaker(textOrAlias);
|
|
112
109
|
await this.element.fill("");
|
|
113
110
|
await this.element.fill(text, options);
|
|
114
111
|
this.data.lastTyped = text;
|
|
115
|
-
|
|
112
|
+
this.log?.(`โจ๏ธ Typed "${text}" into selected element`);
|
|
116
113
|
};
|
|
117
114
|
When("I type {string}", typeStep);
|
|
118
115
|
When("I type stored {string}", typeStep);
|
|
119
116
|
When("I type random {string}", typeStep);
|
|
120
117
|
When("I set value {string}", async function (valueOrAlias, ...rest) {
|
|
121
|
-
var _a, _b;
|
|
122
118
|
if (!this.element)
|
|
123
119
|
throw new Error("No element selected");
|
|
124
120
|
const maybeTable = rest[0];
|
|
125
|
-
const options =
|
|
121
|
+
const options = maybeTable?.rowsHash ? parseFillOptions(maybeTable) : {};
|
|
126
122
|
const value = valueOrAlias.startsWith("@")
|
|
127
|
-
?
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
? this.data[valueOrAlias.slice(1)] ??
|
|
124
|
+
(() => {
|
|
125
|
+
throw new Error(`No value found for alias "${valueOrAlias}"`);
|
|
126
|
+
})()
|
|
130
127
|
: evaluateFaker(valueOrAlias);
|
|
131
128
|
await this.element.fill(value, options);
|
|
132
129
|
this.data.lastValueSet = value;
|
|
133
|
-
|
|
130
|
+
this.log?.(`๐ Set value to "${value}"`);
|
|
134
131
|
});
|
|
135
132
|
When("I clear", async function () {
|
|
136
|
-
var _a;
|
|
137
133
|
if (!this.element)
|
|
138
134
|
throw new Error("No element selected");
|
|
139
135
|
await this.element.fill("");
|
|
140
|
-
|
|
136
|
+
this.log?.("๐งผ Cleared value of selected element");
|
|
141
137
|
});
|
|
142
138
|
When("I submit", async function (...rest) {
|
|
143
|
-
var _a, _b;
|
|
144
139
|
const maybeTable = rest[0];
|
|
145
|
-
const form =
|
|
140
|
+
const form = this.element ?? this.page.locator("form");
|
|
146
141
|
await form.evaluate((f) => f.submit());
|
|
147
|
-
|
|
142
|
+
this.log?.("๐จ Submitted form");
|
|
148
143
|
});
|
|
149
144
|
When("I select option {string}", async function (option, ...rest) {
|
|
150
|
-
var _a;
|
|
151
145
|
if (!this.element)
|
|
152
146
|
throw new Error("No select element stored");
|
|
153
147
|
const maybeTable = rest[0];
|
|
154
|
-
const options =
|
|
148
|
+
const options = maybeTable?.rowsHash ? parseSelectOptions(maybeTable) : {};
|
|
155
149
|
await this.element.selectOption({ label: option }, options);
|
|
156
|
-
|
|
150
|
+
this.log?.(`๐ฝ Selected option "${option}"`);
|
|
157
151
|
});
|
|
158
152
|
When("I select file {string}", async function (filePath, ...rest) {
|
|
159
|
-
var _a;
|
|
160
153
|
if (!this.element)
|
|
161
154
|
throw new Error("No file input selected");
|
|
162
155
|
const maybeTable = rest[0];
|
|
163
|
-
const options =
|
|
156
|
+
const options = maybeTable?.rowsHash ? parseSelectOptions(maybeTable) : {};
|
|
164
157
|
await this.element.setInputFiles(filePath, options);
|
|
165
|
-
|
|
158
|
+
this.log?.(`๐ Set input file to "${filePath}"`);
|
|
166
159
|
});
|