artes 1.7.4 → 1.7.6

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