artes 1.7.19 → 1.7.21

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.
Files changed (49) hide show
  1. package/README.md +781 -781
  2. package/assets/styles.css +4 -4
  3. package/cucumber.config.js +253 -253
  4. package/docs/ciExecutors.md +198 -198
  5. package/docs/emulationDevicesList.md +152 -152
  6. package/docs/functionDefinitions.md +2401 -2401
  7. package/docs/stepDefinitions.md +435 -435
  8. package/executer.js +266 -266
  9. package/index.js +51 -51
  10. package/package.json +56 -56
  11. package/src/helper/contextManager/browserManager.js +74 -74
  12. package/src/helper/contextManager/requestManager.js +23 -23
  13. package/src/helper/controller/elementController.js +230 -230
  14. package/src/helper/controller/findDuplicateTestNames.js +69 -69
  15. package/src/helper/controller/getEnvInfo.js +97 -97
  16. package/src/helper/controller/getExecutor.js +109 -109
  17. package/src/helper/controller/pomCollector.js +83 -83
  18. package/src/helper/controller/reportCustomizer.js +511 -511
  19. package/src/helper/controller/screenComparer.js +96 -96
  20. package/src/helper/controller/status-formatter.js +137 -137
  21. package/src/helper/controller/testCoverageCalculator.js +111 -111
  22. package/src/helper/executers/cleaner.js +23 -23
  23. package/src/helper/executers/exporter.js +19 -19
  24. package/src/helper/executers/helper.js +193 -193
  25. package/src/helper/executers/projectCreator.js +226 -226
  26. package/src/helper/executers/reportGenerator.js +91 -91
  27. package/src/helper/executers/testRunner.js +28 -28
  28. package/src/helper/executers/versionChecker.js +31 -31
  29. package/src/helper/imports/commons.js +69 -69
  30. package/src/helper/stepFunctions/APIActions.js +582 -582
  31. package/src/helper/stepFunctions/assertions.js +986 -986
  32. package/src/helper/stepFunctions/browserActions.js +87 -87
  33. package/src/helper/stepFunctions/elementInteractions.js +60 -60
  34. package/src/helper/stepFunctions/exporter.js +19 -19
  35. package/src/helper/stepFunctions/frameActions.js +72 -72
  36. package/src/helper/stepFunctions/keyboardActions.js +66 -66
  37. package/src/helper/stepFunctions/mouseActions.js +84 -84
  38. package/src/helper/stepFunctions/pageActions.js +43 -43
  39. package/src/hooks/context.js +18 -18
  40. package/src/hooks/hooks.js +287 -287
  41. package/src/stepDefinitions/API.steps.js +404 -404
  42. package/src/stepDefinitions/assertions.steps.js +1358 -1351
  43. package/src/stepDefinitions/browser.steps.js +74 -74
  44. package/src/stepDefinitions/frameActions.steps.js +76 -76
  45. package/src/stepDefinitions/keyboardActions.steps.js +264 -264
  46. package/src/stepDefinitions/mouseActions.steps.js +374 -374
  47. package/src/stepDefinitions/page.steps.js +71 -71
  48. package/src/stepDefinitions/random.steps.js +199 -199
  49. package/src/stepDefinitions/report.steps.js +5 -5
@@ -1,374 +1,374 @@
1
- const {
2
- When,
3
- element,
4
- selector,
5
- context,
6
- resolveVariable,
7
- } = require("../helper/imports/commons");
8
- const { mouse, frame, page } = require("../helper/stepFunctions/exporter");
9
-
10
- // User clicks on a selector
11
- When("User clicks {string}", async function (selector) {
12
- await mouse.click(selector);
13
- });
14
-
15
- When("User clicks last of {string}", async (selector) => {
16
- const elementCount = await frame.count(selector);
17
- const lastElement = await frame.nth(selector, elementCount);
18
- await mouse.click(lastElement);
19
- });
20
-
21
- When("User clicks {int} th of {string}", async (order, elements) => {
22
- const nthElement = await frame.nth(elements, order);
23
- await nthElement.click();
24
- });
25
-
26
- When("User clicks multiple {string}", async (elements) => {
27
- const elementCount = await frame.count(elements);
28
-
29
- for (let i = 0; i < elementCount; i++) {
30
- await frame.nth(elements, i).click();
31
- }
32
- });
33
-
34
- // User clicks on a selector with force
35
- When("User clicks {string} with force", async function (selector) {
36
- await mouse.click(selector, { force: true });
37
- });
38
-
39
- // User clicks on a selector at a specific position
40
- When(
41
- "User clicks {string} at {int}, {int} position",
42
- async function (selector, x, y) {
43
- x = await resolveVariable(x);
44
- y = await resolveVariable(y);
45
- await mouse.click(selector, { position: { x: x, y: y } });
46
- },
47
- );
48
-
49
- // User clicks on a selector at a specific position with force
50
- When(
51
- "User clicks {string} at {int}, {int} position with force",
52
- async function (selector, x, y) {
53
- x = await resolveVariable(x);
54
- y = await resolveVariable(y);
55
- await mouse.click(selector, { force: true, position: { x: x, y: y } });
56
- },
57
- );
58
-
59
- // User clicks at specific coordinates
60
- When("User clicks at {int}, {int} coordinates", async function (x, y) {
61
- x = await resolveVariable(x);
62
- y = await resolveVariable(y);
63
- await context.page.mouse.click(x, y);
64
- });
65
-
66
- // User clicks at specific coordinates with click count and delay
67
- When(
68
- "User clicks at {int}, {int} coordinates with click count {int} and delay {int}",
69
- async function (x, y, clickCount, delay) {
70
- x = await resolveVariable(x);
71
- y = await resolveVariable(y);
72
- await context.page.mouse.click(x, y, { clickCount: clickCount, delay: delay });
73
- },
74
- );
75
-
76
- // User clicks at specific coordinates with force
77
- When(
78
- "User clicks at {int}, {int} coordinates with force",
79
- async function (x, y) {
80
- x = await resolveVariable(x);
81
- y = await resolveVariable(y);
82
- await context.page.mouse.click(x, y, { force: true });
83
- },
84
- );
85
-
86
- // User clicks on a selector with a specific mouse button
87
- When(
88
- "User clicks {string} with {string} button",
89
- async function (selector, button) {
90
- await mouse.click(selector, { button: button });
91
- },
92
- );
93
-
94
- // User clicks on a selector with a specific mouse button and force
95
- When(
96
- "User clicks {string} with {string} button and force",
97
- async function (selector, button) {
98
- await mouse.click(selector, { button: button, force: true });
99
- },
100
- );
101
-
102
- When(
103
- "User clicks multiple {string} with {string} button",
104
- async function (selector, button) {
105
- const elementCount = await frame.count(selector);
106
-
107
- for (let i = 0; i < elementCount; i++) {
108
- await frame.nth(selector, i).click({ button: button });
109
- }
110
- },
111
- );
112
-
113
- // User double clicks on a selector
114
- When("User double clicks {string}", async function (selector) {
115
- await mouse.doubleClick(selector);
116
- });
117
-
118
- When(
119
- "User double clicks {string} with {string} button",
120
- async function (selector, button) {
121
- await mouse.doubleClick(selector, { button: button });
122
- },
123
- );
124
-
125
- When(
126
- "User double clicks {string} with {string} button and force",
127
- async function (selector, button) {
128
- await mouse.doubleClick(selector, { button: button, force: true });
129
- },
130
- );
131
-
132
- When("User double clicks multiple {string}", async (elements) => {
133
- const elementCount = await frame.count(elements);
134
-
135
- for (let i = 0; i < elementCount; i++) {
136
- await frame.nth(elements, i).dblclick();
137
- }
138
- });
139
-
140
- // User double clicks on a selector with force
141
- When("User double clicks {string} with force", async function (selector) {
142
- await mouse.doubleClick(selector, { force: true });
143
- });
144
-
145
- // User double clicks on a selector at a specific position
146
- When(
147
- "User double clicks {string} at {int}, {int} position",
148
- async function (selector, x, y) {
149
- x = await resolveVariable(x);
150
- y = await resolveVariable(y);
151
- await mouse.doubleClick(selector, { position: { x: x, y: y } });
152
- },
153
- );
154
-
155
- // User double clicks on a selector at a specific position with force
156
- When(
157
- "User double clicks {string} at {int}, {int} position with force",
158
- async function (selector, x, y) {
159
- x = await resolveVariable(x);
160
- y = await resolveVariable(y);
161
- await mouse.doubleClick(selector, {
162
- position: { x: x, y: y },
163
- force: true,
164
- });
165
- },
166
- );
167
-
168
- // User double clicks at specific coordinates
169
- When("User double clicks at {int}, {int} coordinates", async function (x, y) {
170
- x = await resolveVariable(x);
171
- y = await resolveVariable(y);
172
- await context.page.doubleClick({ position: { x: x, y: y } });
173
- });
174
-
175
- // User double clicks at specific coordinates with click count and delay
176
- When(
177
- "User double clicks at {int}, {int} coordinates with click count {int} and delay {int}",
178
- async function (x, y, clickCount, delay) {
179
- x = await resolveVariable(x);
180
- y = await resolveVariable(y);
181
- await context.page.doubleClick({
182
- position: { x: x, y: y },
183
- clickCount: clickCount,
184
- delay: delay,
185
- });
186
- },
187
- );
188
-
189
- // User double clicks at specific coordinates with force
190
- When(
191
- "User double clicks at {int}, {int} coordinates with force",
192
- async function (x, y) {
193
- x = await resolveVariable(x);
194
- y = await resolveVariable(y);
195
- await context.page.doubleClick({ position: { x: x, y: y }, force: true });
196
- },
197
- );
198
-
199
- // User moves the mouse to specific coordinates
200
- When("User moves to {int}, {int} coordinates", async function (x, y) {
201
- x = await resolveVariable(x);
202
- y = await resolveVariable(y);
203
- await context.page.move({ position: { x: x, y: y } });
204
- });
205
-
206
- // User scrolls the mouse wheel at specific coordinates
207
- When(
208
- "User scrolls the mouse wheel at {int}, {int} coordinates",
209
- async function (x, y) {
210
- x = await resolveVariable(x);
211
- y = await resolveVariable(y);
212
- await context.page.wheel({ position: { x: x, y: y } });
213
- },
214
- );
215
-
216
- // User hovers over a selector
217
- When("User hovers over {string}", async function (selector) {
218
- await mouse.hover(selector);
219
- });
220
-
221
- // User hovers over a selector with force
222
- When("User hovers over {string} with force", async function (selector) {
223
- await mouse.hover(selector, { force: true });
224
- });
225
-
226
- // User hovers over a selector at a specific position
227
- When(
228
- "User hovers over {string} at {int}, {int} position",
229
- async function (selector, x, y) {
230
- x = await resolveVariable(x);
231
- y = await resolveVariable(y);
232
- await mouse.hover(selector, { position: { x: x, y: y } });
233
- },
234
- );
235
-
236
- // User hovers over a selector at a specific position with force
237
- When(
238
- "User hovers over {string} at {int}, {int} position with force",
239
- async function (selector, x, y) {
240
- x = await resolveVariable(x);
241
- y = await resolveVariable(y);
242
- await mouse.hover(selector, { position: { x: x, y: y }, force: true });
243
- },
244
- );
245
-
246
- // User focuses on a selector
247
- When("User focuses on {string}", async function (selector) {
248
- await mouse.focus(selector);
249
- });
250
-
251
- // User focuses on a selector with force
252
- When("User focuses on {string} with force", async function (selector) {
253
- await mouse.focus(selector, { force: true });
254
- });
255
-
256
- // User focuses on a selector at a specific position
257
- When(
258
- "User focuses on {string} at {int}, {int} position",
259
- async function (selector, x, y) {
260
- x = await resolveVariable(x);
261
- y = await resolveVariable(y);
262
- await mouse.focus(selector, { position: { x: x, y: y } });
263
- },
264
- );
265
-
266
- // User focuses on a selector at a specific position with force
267
- When(
268
- "User focuses on {string} at {int}, {int} position with force",
269
- async function (selector, x, y) {
270
- x = await resolveVariable(x);
271
- y = await resolveVariable(y);
272
- await mouse.focus(selector, { position: { x: x, y: y }, force: true });
273
- },
274
- );
275
-
276
- // User drags an element from one selector to another
277
- When(
278
- "User drags {string} to {string}",
279
- async function (sourceSelector, targetSelector) {
280
- await mouse.dragAndDrop(sourceSelector, targetSelector);
281
- },
282
- );
283
-
284
- // User drags an element to a specific position
285
- When(
286
- "User drags {string} to {int}, {int} position",
287
- async function (sourceSelector, x, y) {
288
- x = await resolveVariable(x);
289
- y = await resolveVariable(y);
290
- await mouse.dragAndDrop(sourceSelector, { position: { x: x, y: y } });
291
- },
292
- );
293
-
294
- // User selects options by value
295
- When(
296
- "User selects by value {string} from {string}",
297
- async function (value, selector) {
298
- await mouse.selectByValue(selector, value);
299
- },
300
- );
301
-
302
- // User selects an option by text
303
- When(
304
- "User selects by text {string} from {string}",
305
- async function (text, selector) {
306
- await mouse.selectByText(selector, text);
307
- },
308
- );
309
-
310
- // User checks a checkbox or radio button
311
- When("User checks {string}", async function (selector) {
312
- await mouse.check(selector);
313
- });
314
-
315
- When("User checks multiple {string}", async function (selectors) {
316
- const elementCount = await frame.count(selectors);
317
-
318
- for (let i = 0; i < elementCount; i++) {
319
- await frame.nth(selectors, i).check();
320
- }
321
- });
322
-
323
- // User unchecks a checkbox or radio button
324
- When("User unchecks {string}", async function (selector) {
325
- await mouse.uncheck(selector);
326
- });
327
-
328
- When("User unchecks multiple {string}", async function (selectors) {
329
- const elementCount = await frame.count(selectors);
330
-
331
- for (let i = 0; i < elementCount; i++) {
332
- await frame.nth(selectors, i).uncheck();
333
- }
334
- });
335
-
336
- // User scrolls into view if needed for a selector
337
- When("User scrolls {string} into view", async function (selector) {
338
- await mouse.scrollIntoViewIfNeeded(selector);
339
- });
340
-
341
- // User uploads file
342
- When("User uploads {string} file to {string}", async (filePath, fileInput) => {
343
- await mouse.upload(filePath, fileInput);
344
- });
345
-
346
- When("User selects by text from {string} randomly", async (select) => {
347
- const optionsArray = await element(`${selector(select)} option`).evaluateAll(
348
- (options) => options.map((option) => option.text),
349
- );
350
- const randomOption =
351
- await optionsArray[Math.floor(Math.random() * optionsArray.length)];
352
-
353
- await mouse.selectByText(select, randomOption);
354
- });
355
-
356
- When("User selects by value from {string} randomly", async (select) => {
357
- const optionsArray = await element(`${selector(select)} option`).evaluateAll(
358
- (options) => options.map((option) => option.value),
359
- );
360
- const randomOption =
361
- await optionsArray[Math.floor(Math.random() * optionsArray.length)];
362
-
363
- await mouse.selectByValue(select, randomOption);
364
- });
365
-
366
- When("User clicks either {string} or {string}", async (element, element2) => {
367
- await page.wait(1000);
368
- const countOfElement = await frame.count(element);
369
- if (countOfElement > 0) {
370
- await mouse.click(element);
371
- } else {
372
- await mouse.click(element2);
373
- }
374
- });
1
+ const {
2
+ When,
3
+ element,
4
+ selector,
5
+ context,
6
+ resolveVariable,
7
+ } = require("../helper/imports/commons");
8
+ const { mouse, frame, page } = require("../helper/stepFunctions/exporter");
9
+
10
+ // User clicks on a selector
11
+ When("User clicks {string}", async function (selector) {
12
+ await mouse.click(selector);
13
+ });
14
+
15
+ When("User clicks last of {string}", async (selector) => {
16
+ const elementCount = await frame.count(selector);
17
+ const lastElement = await frame.nth(selector, elementCount);
18
+ await mouse.click(lastElement);
19
+ });
20
+
21
+ When("User clicks {int} th of {string}", async (order, elements) => {
22
+ const nthElement = await frame.nth(elements, order);
23
+ await nthElement.click();
24
+ });
25
+
26
+ When("User clicks multiple {string}", async (elements) => {
27
+ const elementCount = await frame.count(elements);
28
+
29
+ for (let i = 0; i < elementCount; i++) {
30
+ await frame.nth(elements, i).click();
31
+ }
32
+ });
33
+
34
+ // User clicks on a selector with force
35
+ When("User clicks {string} with force", async function (selector) {
36
+ await mouse.click(selector, { force: true });
37
+ });
38
+
39
+ // User clicks on a selector at a specific position
40
+ When(
41
+ "User clicks {string} at {int}, {int} position",
42
+ async function (selector, x, y) {
43
+ x = await resolveVariable(x);
44
+ y = await resolveVariable(y);
45
+ await mouse.click(selector, { position: { x: x, y: y } });
46
+ },
47
+ );
48
+
49
+ // User clicks on a selector at a specific position with force
50
+ When(
51
+ "User clicks {string} at {int}, {int} position with force",
52
+ async function (selector, x, y) {
53
+ x = await resolveVariable(x);
54
+ y = await resolveVariable(y);
55
+ await mouse.click(selector, { force: true, position: { x: x, y: y } });
56
+ },
57
+ );
58
+
59
+ // User clicks at specific coordinates
60
+ When("User clicks at {int}, {int} coordinates", async function (x, y) {
61
+ x = await resolveVariable(x);
62
+ y = await resolveVariable(y);
63
+ await context.page.mouse.click(x, y);
64
+ });
65
+
66
+ // User clicks at specific coordinates with click count and delay
67
+ When(
68
+ "User clicks at {int}, {int} coordinates with click count {int} and delay {int}",
69
+ async function (x, y, clickCount, delay) {
70
+ x = await resolveVariable(x);
71
+ y = await resolveVariable(y);
72
+ await context.page.mouse.click(x, y, { clickCount: clickCount, delay: delay });
73
+ },
74
+ );
75
+
76
+ // User clicks at specific coordinates with force
77
+ When(
78
+ "User clicks at {int}, {int} coordinates with force",
79
+ async function (x, y) {
80
+ x = await resolveVariable(x);
81
+ y = await resolveVariable(y);
82
+ await context.page.mouse.click(x, y, { force: true });
83
+ },
84
+ );
85
+
86
+ // User clicks on a selector with a specific mouse button
87
+ When(
88
+ "User clicks {string} with {string} button",
89
+ async function (selector, button) {
90
+ await mouse.click(selector, { button: button });
91
+ },
92
+ );
93
+
94
+ // User clicks on a selector with a specific mouse button and force
95
+ When(
96
+ "User clicks {string} with {string} button and force",
97
+ async function (selector, button) {
98
+ await mouse.click(selector, { button: button, force: true });
99
+ },
100
+ );
101
+
102
+ When(
103
+ "User clicks multiple {string} with {string} button",
104
+ async function (selector, button) {
105
+ const elementCount = await frame.count(selector);
106
+
107
+ for (let i = 0; i < elementCount; i++) {
108
+ await frame.nth(selector, i).click({ button: button });
109
+ }
110
+ },
111
+ );
112
+
113
+ // User double clicks on a selector
114
+ When("User double clicks {string}", async function (selector) {
115
+ await mouse.doubleClick(selector);
116
+ });
117
+
118
+ When(
119
+ "User double clicks {string} with {string} button",
120
+ async function (selector, button) {
121
+ await mouse.doubleClick(selector, { button: button });
122
+ },
123
+ );
124
+
125
+ When(
126
+ "User double clicks {string} with {string} button and force",
127
+ async function (selector, button) {
128
+ await mouse.doubleClick(selector, { button: button, force: true });
129
+ },
130
+ );
131
+
132
+ When("User double clicks multiple {string}", async (elements) => {
133
+ const elementCount = await frame.count(elements);
134
+
135
+ for (let i = 0; i < elementCount; i++) {
136
+ await frame.nth(elements, i).dblclick();
137
+ }
138
+ });
139
+
140
+ // User double clicks on a selector with force
141
+ When("User double clicks {string} with force", async function (selector) {
142
+ await mouse.doubleClick(selector, { force: true });
143
+ });
144
+
145
+ // User double clicks on a selector at a specific position
146
+ When(
147
+ "User double clicks {string} at {int}, {int} position",
148
+ async function (selector, x, y) {
149
+ x = await resolveVariable(x);
150
+ y = await resolveVariable(y);
151
+ await mouse.doubleClick(selector, { position: { x: x, y: y } });
152
+ },
153
+ );
154
+
155
+ // User double clicks on a selector at a specific position with force
156
+ When(
157
+ "User double clicks {string} at {int}, {int} position with force",
158
+ async function (selector, x, y) {
159
+ x = await resolveVariable(x);
160
+ y = await resolveVariable(y);
161
+ await mouse.doubleClick(selector, {
162
+ position: { x: x, y: y },
163
+ force: true,
164
+ });
165
+ },
166
+ );
167
+
168
+ // User double clicks at specific coordinates
169
+ When("User double clicks at {int}, {int} coordinates", async function (x, y) {
170
+ x = await resolveVariable(x);
171
+ y = await resolveVariable(y);
172
+ await context.page.doubleClick({ position: { x: x, y: y } });
173
+ });
174
+
175
+ // User double clicks at specific coordinates with click count and delay
176
+ When(
177
+ "User double clicks at {int}, {int} coordinates with click count {int} and delay {int}",
178
+ async function (x, y, clickCount, delay) {
179
+ x = await resolveVariable(x);
180
+ y = await resolveVariable(y);
181
+ await context.page.doubleClick({
182
+ position: { x: x, y: y },
183
+ clickCount: clickCount,
184
+ delay: delay,
185
+ });
186
+ },
187
+ );
188
+
189
+ // User double clicks at specific coordinates with force
190
+ When(
191
+ "User double clicks at {int}, {int} coordinates with force",
192
+ async function (x, y) {
193
+ x = await resolveVariable(x);
194
+ y = await resolveVariable(y);
195
+ await context.page.doubleClick({ position: { x: x, y: y }, force: true });
196
+ },
197
+ );
198
+
199
+ // User moves the mouse to specific coordinates
200
+ When("User moves to {int}, {int} coordinates", async function (x, y) {
201
+ x = await resolveVariable(x);
202
+ y = await resolveVariable(y);
203
+ await context.page.move({ position: { x: x, y: y } });
204
+ });
205
+
206
+ // User scrolls the mouse wheel at specific coordinates
207
+ When(
208
+ "User scrolls the mouse wheel at {int}, {int} coordinates",
209
+ async function (x, y) {
210
+ x = await resolveVariable(x);
211
+ y = await resolveVariable(y);
212
+ await context.page.wheel({ position: { x: x, y: y } });
213
+ },
214
+ );
215
+
216
+ // User hovers over a selector
217
+ When("User hovers over {string}", async function (selector) {
218
+ await mouse.hover(selector);
219
+ });
220
+
221
+ // User hovers over a selector with force
222
+ When("User hovers over {string} with force", async function (selector) {
223
+ await mouse.hover(selector, { force: true });
224
+ });
225
+
226
+ // User hovers over a selector at a specific position
227
+ When(
228
+ "User hovers over {string} at {int}, {int} position",
229
+ async function (selector, x, y) {
230
+ x = await resolveVariable(x);
231
+ y = await resolveVariable(y);
232
+ await mouse.hover(selector, { position: { x: x, y: y } });
233
+ },
234
+ );
235
+
236
+ // User hovers over a selector at a specific position with force
237
+ When(
238
+ "User hovers over {string} at {int}, {int} position with force",
239
+ async function (selector, x, y) {
240
+ x = await resolveVariable(x);
241
+ y = await resolveVariable(y);
242
+ await mouse.hover(selector, { position: { x: x, y: y }, force: true });
243
+ },
244
+ );
245
+
246
+ // User focuses on a selector
247
+ When("User focuses on {string}", async function (selector) {
248
+ await mouse.focus(selector);
249
+ });
250
+
251
+ // User focuses on a selector with force
252
+ When("User focuses on {string} with force", async function (selector) {
253
+ await mouse.focus(selector, { force: true });
254
+ });
255
+
256
+ // User focuses on a selector at a specific position
257
+ When(
258
+ "User focuses on {string} at {int}, {int} position",
259
+ async function (selector, x, y) {
260
+ x = await resolveVariable(x);
261
+ y = await resolveVariable(y);
262
+ await mouse.focus(selector, { position: { x: x, y: y } });
263
+ },
264
+ );
265
+
266
+ // User focuses on a selector at a specific position with force
267
+ When(
268
+ "User focuses on {string} at {int}, {int} position with force",
269
+ async function (selector, x, y) {
270
+ x = await resolveVariable(x);
271
+ y = await resolveVariable(y);
272
+ await mouse.focus(selector, { position: { x: x, y: y }, force: true });
273
+ },
274
+ );
275
+
276
+ // User drags an element from one selector to another
277
+ When(
278
+ "User drags {string} to {string}",
279
+ async function (sourceSelector, targetSelector) {
280
+ await mouse.dragAndDrop(sourceSelector, targetSelector);
281
+ },
282
+ );
283
+
284
+ // User drags an element to a specific position
285
+ When(
286
+ "User drags {string} to {int}, {int} position",
287
+ async function (sourceSelector, x, y) {
288
+ x = await resolveVariable(x);
289
+ y = await resolveVariable(y);
290
+ await mouse.dragAndDrop(sourceSelector, { position: { x: x, y: y } });
291
+ },
292
+ );
293
+
294
+ // User selects options by value
295
+ When(
296
+ "User selects by value {string} from {string}",
297
+ async function (value, selector) {
298
+ await mouse.selectByValue(selector, value);
299
+ },
300
+ );
301
+
302
+ // User selects an option by text
303
+ When(
304
+ "User selects by text {string} from {string}",
305
+ async function (text, selector) {
306
+ await mouse.selectByText(selector, text);
307
+ },
308
+ );
309
+
310
+ // User checks a checkbox or radio button
311
+ When("User checks {string}", async function (selector) {
312
+ await mouse.check(selector);
313
+ });
314
+
315
+ When("User checks multiple {string}", async function (selectors) {
316
+ const elementCount = await frame.count(selectors);
317
+
318
+ for (let i = 0; i < elementCount; i++) {
319
+ await frame.nth(selectors, i).check();
320
+ }
321
+ });
322
+
323
+ // User unchecks a checkbox or radio button
324
+ When("User unchecks {string}", async function (selector) {
325
+ await mouse.uncheck(selector);
326
+ });
327
+
328
+ When("User unchecks multiple {string}", async function (selectors) {
329
+ const elementCount = await frame.count(selectors);
330
+
331
+ for (let i = 0; i < elementCount; i++) {
332
+ await frame.nth(selectors, i).uncheck();
333
+ }
334
+ });
335
+
336
+ // User scrolls into view if needed for a selector
337
+ When("User scrolls {string} into view", async function (selector) {
338
+ await mouse.scrollIntoViewIfNeeded(selector);
339
+ });
340
+
341
+ // User uploads file
342
+ When("User uploads {string} file to {string}", async (filePath, fileInput) => {
343
+ await mouse.upload(filePath, fileInput);
344
+ });
345
+
346
+ When("User selects by text from {string} randomly", async (select) => {
347
+ const optionsArray = await element(`${selector(select)} option`).evaluateAll(
348
+ (options) => options.map((option) => option.text),
349
+ );
350
+ const randomOption =
351
+ await optionsArray[Math.floor(Math.random() * optionsArray.length)];
352
+
353
+ await mouse.selectByText(select, randomOption);
354
+ });
355
+
356
+ When("User selects by value from {string} randomly", async (select) => {
357
+ const optionsArray = await element(`${selector(select)} option`).evaluateAll(
358
+ (options) => options.map((option) => option.value),
359
+ );
360
+ const randomOption =
361
+ await optionsArray[Math.floor(Math.random() * optionsArray.length)];
362
+
363
+ await mouse.selectByValue(select, randomOption);
364
+ });
365
+
366
+ When("User clicks either {string} or {string}", async (element, element2) => {
367
+ await page.wait(1000);
368
+ const countOfElement = await frame.count(element);
369
+ if (countOfElement > 0) {
370
+ await mouse.click(element);
371
+ } else {
372
+ await mouse.click(element2);
373
+ }
374
+ });