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.
@@ -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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, "๐Ÿ–ฑ๏ธ Clicked on stored element");
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked on button "${label}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `โœ… Clicked on link "${text}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿท๏ธ Clicked on label "${labelText}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked on text "${text}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked on exact text "${exactText}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked element #${i + 1}`);
73
+ this.log?.(`๐Ÿ–ฑ๏ธ Clicked element #${i + 1}`);
81
74
  }
82
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `โœ… Clicked all ${count} elements.`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
79
+ const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
88
80
  const element = this.element || this.page.getByText(text);
89
81
  await element.dblclick(options);
90
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Double-clicked on text "${text}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
86
+ const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
96
87
  await this.page.mouse.dblclick(x, y, options);
97
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Double-clicked at (${x}, ${y})`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, "๐Ÿ–ฑ๏ธ Double-clicked on stored element");
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, "๐Ÿ–ฑ๏ธ Right-clicked on stored element");
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
108
+ const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
121
109
  const element = this.page.getByText(text);
122
110
  await element.click({ button: "right", ...options });
123
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Right-clicked on text "${text}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseClickOptions(maybeTable) : {};
115
+ const options = maybeTable?.rowsHash ? parseClickOptions(maybeTable) : {};
129
116
  await this.page.mouse.click(x, y, { button: "right", ...options });
130
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Right-clicked at (${x}, ${y})`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, "๐ŸŒ€ Blurred active element");
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, "๐ŸŽฏ Focused stored element");
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked element #${i + 1}`);
147
+ this.log?.(`๐Ÿ–ฑ๏ธ Clicked element #${i + 1}`);
164
148
  }
165
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `โœ… Clicked all ${count} stored elements.`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked on selector: ${selector}`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Found ${count} elements with selector ${selector}`);
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 = (_a = this.data) === null || _a === void 0 ? void 0 : _a[alias];
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
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `๐Ÿ”˜ Stored all buttons matching text "${buttonText}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Selected ${index} element from stored elements`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored ${count} elements with role "${role}"`);
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 === null || text === void 0 ? void 0 : text.trim();
138
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored text "${text}" as "${alias}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored textarea with label "${label}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored textarea with placeholder "${placeholder}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple textareas with label "${label}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored textarea with name "${name}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple textareas with ID "${id}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored input with ID "${id}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple inputs with ID "${id}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple textareas with placeholder "${placeholder}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored input with label "${label}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored input with name "${name}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored input with placeholder "${placeholder}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple inputs with name "${name}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple inputs with placeholder "${placeholder}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `Stored multiple inputs with label "${label}"`);
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 = (_a = this.data) === null || _a === void 0 ? void 0 : _a[alias];
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
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `๐Ÿ“ฆ Stored multiple inputs with display value "${value}"`);
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 = (_a = this.data) === null || _a === void 0 ? void 0 : _a[alias];
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
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `๐Ÿ” Found input with value: "${value}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseCheckOptions(maybeTable) : {};
12
- await ((_a = this.element) === null || _a === void 0 ? void 0 : _a.check(options));
13
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, "โœ… Checked stored checkbox");
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseCheckOptions(maybeTable) : {};
19
- await ((_a = this.element) === null || _a === void 0 ? void 0 : _a.uncheck(options));
20
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, "โœ… Unchecked stored checkbox");
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseCheckOptions(maybeTable) : {};
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseCheckOptions(maybeTable) : {};
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 = (maybeOptionsTable === null || maybeOptionsTable === void 0 ? void 0 : maybeOptionsTable.rowsHash)
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ–ฑ๏ธ Clicked on "${rawTarget}"`);
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
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `๐Ÿ“ Uploaded file to "${rawTarget}": ${resolvedValue}`);
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 = (maybeOptionsTable === null || maybeOptionsTable === void 0 ? void 0 : maybeOptionsTable.rowsHash)
81
+ const fillOptions = maybeOptionsTable?.rowsHash
85
82
  ? parseFillOptions(maybeOptionsTable)
86
83
  : {};
87
84
  if (inputText) {
88
85
  await element.fill(inputText, fillOptions);
89
- (_c = this.log) === null || _c === void 0 ? void 0 : _c.call(this, `โŒจ๏ธ Filled "${rawTarget}" with: ${inputText}`);
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
- (_d = this.log) === null || _d === void 0 ? void 0 : _d.call(this, `๐ŸŽน Pressed {${key}} on "${rawTarget}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseFillOptions(maybeTable) : {};
102
+ const options = maybeTable?.rowsHash ? parseFillOptions(maybeTable) : {};
107
103
  const text = textOrAlias.startsWith("@")
108
- ? (_a = this.data[textOrAlias.slice(1)]) !== null && _a !== void 0 ? _a : (() => {
109
- throw new Error(`No value found for alias "${textOrAlias}"`);
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
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `โŒจ๏ธ Typed "${text}" into selected element`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseFillOptions(maybeTable) : {};
121
+ const options = maybeTable?.rowsHash ? parseFillOptions(maybeTable) : {};
126
122
  const value = valueOrAlias.startsWith("@")
127
- ? (_a = this.data[valueOrAlias.slice(1)]) !== null && _a !== void 0 ? _a : (() => {
128
- throw new Error(`No value found for alias "${valueOrAlias}"`);
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
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, `๐Ÿ“ Set value to "${value}"`);
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
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, "๐Ÿงผ Cleared value of selected element");
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 = (_a = this.element) !== null && _a !== void 0 ? _a : this.page.locator("form");
140
+ const form = this.element ?? this.page.locator("form");
146
141
  await form.evaluate((f) => f.submit());
147
- (_b = this.log) === null || _b === void 0 ? void 0 : _b.call(this, "๐Ÿ“จ Submitted form");
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseSelectOptions(maybeTable) : {};
148
+ const options = maybeTable?.rowsHash ? parseSelectOptions(maybeTable) : {};
155
149
  await this.element.selectOption({ label: option }, options);
156
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ”ฝ Selected option "${option}"`);
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 = (maybeTable === null || maybeTable === void 0 ? void 0 : maybeTable.rowsHash) ? parseSelectOptions(maybeTable) : {};
156
+ const options = maybeTable?.rowsHash ? parseSelectOptions(maybeTable) : {};
164
157
  await this.element.setInputFiles(filePath, options);
165
- (_a = this.log) === null || _a === void 0 ? void 0 : _a.call(this, `๐Ÿ“ Set input file to "${filePath}"`);
158
+ this.log?.(`๐Ÿ“ Set input file to "${filePath}"`);
166
159
  });