playwright-cucumber-ts-steps 1.1.12 → 1.2.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.
Files changed (84) hide show
  1. package/README.md +1697 -2
  2. package/dist/backend/actions/click.d.ts +55 -77
  3. package/dist/backend/actions/click.d.ts.map +1 -1
  4. package/dist/backend/actions/click.js +125 -103
  5. package/dist/backend/actions/find.d.ts +48 -121
  6. package/dist/backend/actions/find.d.ts.map +1 -1
  7. package/dist/backend/actions/find.js +126 -172
  8. package/dist/backend/actions/form.d.ts +18 -26
  9. package/dist/backend/actions/form.d.ts.map +1 -1
  10. package/dist/backend/actions/form.js +30 -35
  11. package/dist/backend/actions/formTable.d.ts +4 -9
  12. package/dist/backend/actions/formTable.d.ts.map +1 -1
  13. package/dist/backend/actions/formTable.js +13 -11
  14. package/dist/backend/actions/frames.d.ts +7 -35
  15. package/dist/backend/actions/frames.d.ts.map +1 -1
  16. package/dist/backend/actions/frames.js +22 -61
  17. package/dist/backend/actions/index.d.ts +0 -1
  18. package/dist/backend/actions/index.d.ts.map +1 -1
  19. package/dist/backend/actions/index.js +0 -1
  20. package/dist/backend/actions/inputs.d.ts +33 -77
  21. package/dist/backend/actions/inputs.d.ts.map +1 -1
  22. package/dist/backend/actions/inputs.js +92 -116
  23. package/dist/backend/actions/interactions.d.ts +10 -32
  24. package/dist/backend/actions/interactions.d.ts.map +1 -1
  25. package/dist/backend/actions/interactions.js +31 -41
  26. package/dist/backend/actions/keyboard.d.ts +13 -37
  27. package/dist/backend/actions/keyboard.d.ts.map +1 -1
  28. package/dist/backend/actions/keyboard.js +35 -46
  29. package/dist/backend/actions/misc.d.ts +29 -69
  30. package/dist/backend/actions/misc.d.ts.map +1 -1
  31. package/dist/backend/actions/misc.js +77 -98
  32. package/dist/backend/actions/mobile.d.ts +14 -36
  33. package/dist/backend/actions/mobile.d.ts.map +1 -1
  34. package/dist/backend/actions/mobile.js +42 -55
  35. package/dist/backend/actions/mouse.d.ts +29 -36
  36. package/dist/backend/actions/mouse.d.ts.map +1 -1
  37. package/dist/backend/actions/mouse.js +76 -51
  38. package/dist/backend/actions/navigation.d.ts +11 -23
  39. package/dist/backend/actions/navigation.d.ts.map +1 -1
  40. package/dist/backend/actions/navigation.js +32 -32
  41. package/dist/backend/actions/waits.d.ts +11 -30
  42. package/dist/backend/actions/waits.d.ts.map +1 -1
  43. package/dist/backend/actions/waits.js +32 -39
  44. package/dist/backend/api/assertions.d.ts +6 -15
  45. package/dist/backend/api/assertions.d.ts.map +1 -1
  46. package/dist/backend/api/assertions.js +21 -23
  47. package/dist/backend/api/mock.d.ts +9 -18
  48. package/dist/backend/api/mock.d.ts.map +1 -1
  49. package/dist/backend/api/mock.js +24 -22
  50. package/dist/backend/api/network.d.ts +13 -25
  51. package/dist/backend/api/network.d.ts.map +1 -1
  52. package/dist/backend/api/network.js +40 -39
  53. package/dist/backend/api/requests.d.ts +13 -24
  54. package/dist/backend/api/requests.d.ts.map +1 -1
  55. package/dist/backend/api/requests.js +31 -30
  56. package/dist/backend/assertions/pageState.d.ts +13 -24
  57. package/dist/backend/assertions/pageState.d.ts.map +1 -1
  58. package/dist/backend/assertions/pageState.js +31 -29
  59. package/dist/backend/assertions/text.d.ts +12 -23
  60. package/dist/backend/assertions/text.d.ts.map +1 -1
  61. package/dist/backend/assertions/text.js +30 -28
  62. package/dist/backend/assertions/visibility.d.ts +24 -51
  63. package/dist/backend/assertions/visibility.d.ts.map +1 -1
  64. package/dist/backend/assertions/visibility.js +74 -79
  65. package/dist/backend/auth/index.d.ts +14 -1
  66. package/dist/backend/auth/index.d.ts.map +1 -1
  67. package/dist/backend/auth/index.js +26 -8
  68. package/dist/backend/db/steps.d.ts +58 -18
  69. package/dist/backend/db/steps.d.ts.map +1 -1
  70. package/dist/backend/db/steps.js +180 -26
  71. package/dist/backend/elements/alerts.d.ts +10 -19
  72. package/dist/backend/elements/alerts.d.ts.map +1 -1
  73. package/dist/backend/elements/alerts.js +25 -23
  74. package/dist/backend/elements/forms.d.ts +12 -23
  75. package/dist/backend/elements/forms.d.ts.map +1 -1
  76. package/dist/backend/elements/forms.js +30 -29
  77. package/dist/backend/elements/frames.d.ts +9 -18
  78. package/dist/backend/elements/frames.d.ts.map +1 -1
  79. package/dist/backend/elements/frames.js +24 -23
  80. package/dist/backend/index.d.ts +14 -0
  81. package/dist/backend/index.d.ts.map +1 -0
  82. package/dist/backend/index.js +31 -0
  83. package/dist/metadata.json +1016 -0
  84. package/package.json +8 -4
@@ -1,133 +1,111 @@
1
1
  /**
2
2
  * Clicks on the currently stored (active) element.
3
- *
4
- * ```gherkin
3
+ * @example
5
4
  * When I click
6
- * ```
7
5
  */
8
- export declare const ClickStoredElement: void;
6
+ export declare function clickStoredElement(page: any, table?: any): Promise<void>;
9
7
  /**
10
8
  * Clicks on an element matching the given CSS/XPath selector.
11
- *
12
- * ```gherkin
13
- * When I click on element {string}
14
- * ```
15
- *
9
+ * @example
10
+ * When I click on element ".my-element"
16
11
  * @param selector - The CSS or XPath selector of the element.
17
12
  */
18
- export declare const ClickElementBySelector: void;
13
+ export declare function clickElementBySelector(page: any, selector: string, table?: any): Promise<void>;
19
14
  /**
20
15
  * Clicks on a button role element with the specified label.
21
- *
22
- * ```gherkin
23
- * When I click on button {string}
24
- * ```
25
- *
16
+ * @example
17
+ * When I click on button "Submit"
26
18
  * @param label - The visible text or accessible name of the button.
27
19
  */
28
- export declare const ClickButtonByLabel: void;
20
+ export declare function clickButtonByLabel(page: any, label: string, table?: any): Promise<void>;
29
21
  /**
30
22
  * Clicks on a link role element with the specified text.
31
- *
32
- * ```gherkin
33
- * When I click on link {string}
34
- * ```
35
- *
23
+ * @example
24
+ * When I click on link "Home"
36
25
  * @param text - The visible text of the link.
37
26
  */
38
- export declare const ClickLinkByText: void;
27
+ export declare function clickLinkByText(page: any, text: string, table?: any): Promise<void>;
39
28
  /**
40
29
  * Clicks on a form label element.
41
- *
42
- * ```gherkin
43
- * When I click on label {string}
44
- * ```
45
- *
30
+ * @example
31
+ * When I click on label "Email"
46
32
  * @param labelText - The text content of the label element.
47
33
  */
48
- export declare const ClickLabelByText: void;
34
+ export declare function clickLabelByText(page: any, labelText: string, table?: any): Promise<void>;
49
35
  /**
50
36
  * Clicks on the first visible element containing the specified text (partial match).
51
- *
52
- * ```gherkin
53
- * When I click on text {string}
54
- * ```
55
- *
37
+ * @example
38
+ * When I click on text "Login"
56
39
  * @param rawText - The text to look for. Use "@alias" to reference a stored variable.
57
40
  */
58
- export declare const ClickByText: void;
41
+ export declare function clickByText(page: any, rawText: string, table?: any): Promise<void>;
59
42
  /**
60
43
  * Clicks on an element containing the EXACT specified text.
61
- *
62
- * ```gherkin
63
- * When I click on exact text {string}
64
- * ```
65
- *
44
+ * @example
45
+ * When I click on exact text "Submit"
66
46
  * @param exactText - The exact text content to match.
67
47
  */
68
- export declare const ClickByExactText: void;
48
+ export declare function clickByExactText(page: any, exactText: string, table?: any): Promise<void>;
69
49
  /**
70
50
  * Clicks on a selector provided via Regex match.
71
- *
72
- * ```gherkin
73
- * I click on selector "#btn-id"
74
- * ```
51
+ * @example
52
+ * When I click on selector "#btn-id"
75
53
  */
76
- export declare const ClickByRegexSelector: void;
54
+ export declare function clickByRegexSelector(page: any, selector: string): Promise<void>;
77
55
  /**
78
56
  * Iterates through ALL currently stored active elements and clicks them one by one.
79
- *
80
- * ```gherkin
57
+ * @example
81
58
  * When I click all
82
- * ```
83
59
  */
84
- export declare const ClickAllStoredElements: void;
60
+ export declare function clickAllStoredElements(page: any, table?: any): Promise<void>;
85
61
  /**
86
62
  * Double-clicks on the currently stored (active) element.
87
- *
88
- * ```gherkin
63
+ * @example
89
64
  * When I double click
90
- * ```
91
65
  */
92
- export declare const DoubleClickStoredElement: void;
66
+ export declare function doubleClickStoredElement(page: any, table?: any): Promise<void>;
93
67
  /**
94
68
  * Double-clicks on the first element containing the specified text.
95
- *
96
- * ```gherkin
97
- * When I double click on text {string}
98
- * ```
69
+ * @example
70
+ * When I double click on text "Button"
99
71
  */
100
- export declare const DoubleClickByText: void;
72
+ export declare function doubleClickByText(page: any, text: string, table?: any): Promise<void>;
101
73
  /**
102
74
  * Double-clicks at specific X, Y coordinates on the page.
103
- *
104
- * ```gherkin
105
- * When I double click position {int} {int}
106
- * ```
75
+ * @example
76
+ * When I double click position 100 200
107
77
  */
108
- export declare const DoubleClickPosition: void;
78
+ export declare function doubleClickPosition(page: any, x: number, y: number, table?: any): Promise<void>;
109
79
  /**
110
80
  * Right-clicks (Context Click) on the currently stored element.
111
- *
112
- * ```gherkin
81
+ * @example
113
82
  * When I right click
114
- * ```
115
83
  */
116
- export declare const RightClickStoredElement: void;
84
+ export declare function rightClickStoredElement(page: any, table?: any): Promise<void>;
117
85
  /**
118
86
  * Right-clicks on the first element containing the specified text.
119
- *
120
- * ```gherkin
121
- * When I right click on text {string}
122
- * ```
87
+ * @example
88
+ * When I right click on text "Menu"
123
89
  */
124
- export declare const RightClickByText: void;
90
+ export declare function rightClickByText(page: any, text: string, table?: any): Promise<void>;
125
91
  /**
126
92
  * Right-clicks at specific X, Y coordinates on the page.
127
- *
128
- * ```gherkin
129
- * When I right click position {int} {int}
130
- * ```
93
+ * @example
94
+ * When I right click position 100 200
131
95
  */
132
- export declare const RightClickPosition: void;
96
+ export declare function rightClickPosition(page: any, x: number, y: number, table?: any): Promise<void>;
97
+ /**
98
+ * Clicks on the Nth element containing the specified text.
99
+ * Handles 1st, 2nd, 3rd, 4th, etc.
100
+ * @example
101
+ * When I click on 1st element "Login"
102
+ * When I click on 2nd element "Submit"
103
+ */
104
+ export declare function clickNthElementByText(page: any, indexStr: string, text: string, table?: any): Promise<void>;
105
+ /**
106
+ * Clicks on the Nth element matching a CSS or XPath selector.
107
+ * @example
108
+ * When I click on 1st selector ".btn"
109
+ */
110
+ export declare function clickNthElementBySelector(page: any, indexStr: string, selector: string, table?: any): Promise<void>;
133
111
  //# sourceMappingURL=click.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/click.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,MAK7B,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,MASlC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,MAM7B,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,MAM1B,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,MAS5B,CAAC;AAMF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,MAoBtB,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,MAW5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,MAQhC,CAAC;AAMF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,MAcjC,CAAC;AAMH;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,MAKnC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,MAQ7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,MAO/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,MAKlC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,MAQ5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,MAO9B,CAAC"}
1
+ {"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/click.ts"],"names":[],"mappings":"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"}
@@ -1,101 +1,97 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RightClickPosition = exports.RightClickByText = exports.RightClickStoredElement = exports.DoubleClickPosition = exports.DoubleClickByText = exports.DoubleClickStoredElement = exports.ClickAllStoredElements = exports.ClickByRegexSelector = exports.ClickByExactText = exports.ClickByText = exports.ClickLabelByText = exports.ClickLinkByText = exports.ClickButtonByLabel = exports.ClickElementBySelector = exports.ClickStoredElement = void 0;
3
+ exports.clickStoredElement = clickStoredElement;
4
+ exports.clickElementBySelector = clickElementBySelector;
5
+ exports.clickButtonByLabel = clickButtonByLabel;
6
+ exports.clickLinkByText = clickLinkByText;
7
+ exports.clickLabelByText = clickLabelByText;
8
+ exports.clickByText = clickByText;
9
+ exports.clickByExactText = clickByExactText;
10
+ exports.clickByRegexSelector = clickByRegexSelector;
11
+ exports.clickAllStoredElements = clickAllStoredElements;
12
+ exports.doubleClickStoredElement = doubleClickStoredElement;
13
+ exports.doubleClickByText = doubleClickByText;
14
+ exports.doubleClickPosition = doubleClickPosition;
15
+ exports.rightClickStoredElement = rightClickStoredElement;
16
+ exports.rightClickByText = rightClickByText;
17
+ exports.rightClickPosition = rightClickPosition;
18
+ exports.clickNthElementByText = clickNthElementByText;
19
+ exports.clickNthElementBySelector = clickNthElementBySelector;
4
20
  const registry_1 = require("../../core/registry");
5
21
  const state_1 = require("../utils/state");
6
22
  // ==================================================
7
- // 1. STANDARD CLICKS
23
+ // CORE FUNCTIONS
8
24
  // ==================================================
9
25
  /**
10
26
  * Clicks on the currently stored (active) element.
11
- *
12
- * ```gherkin
27
+ * @example
13
28
  * When I click
14
- * ```
15
29
  */
16
- exports.ClickStoredElement = (0, registry_1.Step)("I click", async (page, table) => {
30
+ async function clickStoredElement(page, table) {
17
31
  const options = (0, state_1.parseClickOptions)(table);
18
32
  const element = (0, state_1.getActiveElement)(page);
19
33
  await element.click(options);
20
34
  console.log("🖱️ Clicked on stored element");
21
- });
35
+ }
22
36
  /**
23
37
  * Clicks on an element matching the given CSS/XPath selector.
24
- *
25
- * ```gherkin
26
- * When I click on element {string}
27
- * ```
28
- *
38
+ * @example
39
+ * When I click on element ".my-element"
29
40
  * @param selector - The CSS or XPath selector of the element.
30
41
  */
31
- exports.ClickElementBySelector = (0, registry_1.Step)("I click on element {string}", async (page, selector, table) => {
42
+ async function clickElementBySelector(page, selector, table) {
32
43
  const options = (0, state_1.parseClickOptions)(table);
33
44
  const element = page.locator(selector);
34
45
  await element.click(options);
35
46
  (0, state_1.setActiveElement)(page, element);
36
47
  console.log(`🖱️ Clicked on element "${selector}"`);
37
- });
48
+ }
38
49
  /**
39
50
  * Clicks on a button role element with the specified label.
40
- *
41
- * ```gherkin
42
- * When I click on button {string}
43
- * ```
44
- *
51
+ * @example
52
+ * When I click on button "Submit"
45
53
  * @param label - The visible text or accessible name of the button.
46
54
  */
47
- exports.ClickButtonByLabel = (0, registry_1.Step)("I click on button {string}", async (page, label, table) => {
55
+ async function clickButtonByLabel(page, label, table) {
48
56
  const options = (0, state_1.parseClickOptions)(table);
49
57
  const button = page.getByRole("button", { name: label });
50
58
  await button.click(options);
51
59
  (0, state_1.setActiveElement)(page, button);
52
60
  console.log(`🖱️ Clicked on button "${label}"`);
53
- });
61
+ }
54
62
  /**
55
63
  * Clicks on a link role element with the specified text.
56
- *
57
- * ```gherkin
58
- * When I click on link {string}
59
- * ```
60
- *
64
+ * @example
65
+ * When I click on link "Home"
61
66
  * @param text - The visible text of the link.
62
67
  */
63
- exports.ClickLinkByText = (0, registry_1.Step)("I click on link {string}", async (page, text, table) => {
68
+ async function clickLinkByText(page, text, table) {
64
69
  const options = (0, state_1.parseClickOptions)(table);
65
70
  const link = page.getByRole("link", { name: text });
66
71
  await link.click(options);
67
72
  (0, state_1.setActiveElement)(page, link);
68
73
  console.log(`✅ Clicked on link "${text}"`);
69
- });
74
+ }
70
75
  /**
71
76
  * Clicks on a form label element.
72
- *
73
- * ```gherkin
74
- * When I click on label {string}
75
- * ```
76
- *
77
+ * @example
78
+ * When I click on label "Email"
77
79
  * @param labelText - The text content of the label element.
78
80
  */
79
- exports.ClickLabelByText = (0, registry_1.Step)("I click on label {string}", async (page, labelText, table) => {
81
+ async function clickLabelByText(page, labelText, table) {
80
82
  const options = (0, state_1.parseClickOptions)(table);
81
83
  const label = page.getByLabel(labelText);
82
84
  await label.click(options);
83
85
  (0, state_1.setActiveElement)(page, label);
84
86
  console.log(`🏷️ Clicked on label "${labelText}"`);
85
- });
86
- // ==================================================
87
- // 2. TEXT-BASED CLICKS
88
- // ==================================================
87
+ }
89
88
  /**
90
89
  * Clicks on the first visible element containing the specified text (partial match).
91
- *
92
- * ```gherkin
93
- * When I click on text {string}
94
- * ```
95
- *
90
+ * @example
91
+ * When I click on text "Login"
96
92
  * @param rawText - The text to look for. Use "@alias" to reference a stored variable.
97
93
  */
98
- exports.ClickByText = (0, registry_1.Step)("I click on text {string}", async (page, rawText, table) => {
94
+ async function clickByText(page, rawText, table) {
99
95
  const options = (0, state_1.parseClickOptions)(table);
100
96
  let text = rawText;
101
97
  // Handle Alias (e.g., "@username")
@@ -112,48 +108,38 @@ exports.ClickByText = (0, registry_1.Step)("I click on text {string}", async (pa
112
108
  await locator.click(options);
113
109
  (0, state_1.setActiveElement)(page, locator);
114
110
  console.log(`🖱️ Clicked on text "${text}"`);
115
- });
111
+ }
116
112
  /**
117
113
  * Clicks on an element containing the EXACT specified text.
118
- *
119
- * ```gherkin
120
- * When I click on exact text {string}
121
- * ```
122
- *
114
+ * @example
115
+ * When I click on exact text "Submit"
123
116
  * @param exactText - The exact text content to match.
124
117
  */
125
- exports.ClickByExactText = (0, registry_1.Step)("I click on exact text {string}", async (page, exactText, table) => {
118
+ async function clickByExactText(page, exactText, table) {
126
119
  const options = (0, state_1.parseClickOptions)(table);
127
120
  const locator = page.getByText(exactText, { exact: true });
128
121
  await locator.waitFor({ state: "visible", timeout: 5000 });
129
122
  await locator.click(options);
130
123
  (0, state_1.setActiveElement)(page, locator);
131
124
  console.log(`🖱️ Clicked on exact text "${exactText}"`);
132
- });
125
+ }
133
126
  /**
134
127
  * Clicks on a selector provided via Regex match.
135
- *
136
- * ```gherkin
137
- * I click on selector "#btn-id"
138
- * ```
128
+ * @example
129
+ * When I click on selector "#btn-id"
139
130
  */
140
- exports.ClickByRegexSelector = (0, registry_1.Step)(/^I click on selector "([^"]+)"$/, async (page, selector) => {
131
+ async function clickByRegexSelector(page, selector) {
141
132
  const locator = page.locator(selector);
142
133
  await locator.click();
143
134
  (0, state_1.setActiveElement)(page, locator);
144
135
  console.log(`🖱️ Clicked on selector: ${selector}`);
145
- });
146
- // ==================================================
147
- // 3. BULK CLICKS
148
- // ==================================================
136
+ }
149
137
  /**
150
138
  * Iterates through ALL currently stored active elements and clicks them one by one.
151
- *
152
- * ```gherkin
139
+ * @example
153
140
  * When I click all
154
- * ```
155
141
  */
156
- exports.ClickAllStoredElements = (0, registry_1.Step)("I click all", async (page, table) => {
142
+ async function clickAllStoredElements(page, table) {
157
143
  const options = (0, state_1.parseClickOptions)(table);
158
144
  const elements = (0, state_1.getActiveElements)(page);
159
145
  const count = await elements.count();
@@ -166,83 +152,119 @@ exports.ClickAllStoredElements = (0, registry_1.Step)("I click all", async (page
166
152
  console.log(`🖱️ Clicked element #${i + 1}`);
167
153
  }
168
154
  console.log(`✅ Clicked all ${count} elements.`);
169
- });
170
- // ==================================================
171
- // 4. MOUSE INTERACTIONS (Double & Right Click)
172
- // ==================================================
155
+ }
173
156
  /**
174
157
  * Double-clicks on the currently stored (active) element.
175
- *
176
- * ```gherkin
158
+ * @example
177
159
  * When I double click
178
- * ```
179
160
  */
180
- exports.DoubleClickStoredElement = (0, registry_1.Step)("I double click", async (page, table) => {
161
+ async function doubleClickStoredElement(page, table) {
181
162
  const options = (0, state_1.parseClickOptions)(table);
182
163
  const element = (0, state_1.getActiveElement)(page);
183
164
  await element.dblclick(options);
184
165
  console.log("🖱️ Double-clicked on stored element");
185
- });
166
+ }
186
167
  /**
187
168
  * Double-clicks on the first element containing the specified text.
188
- *
189
- * ```gherkin
190
- * When I double click on text {string}
191
- * ```
169
+ * @example
170
+ * When I double click on text "Button"
192
171
  */
193
- exports.DoubleClickByText = (0, registry_1.Step)("I double click on text {string}", async (page, text, table) => {
172
+ async function doubleClickByText(page, text, table) {
194
173
  const options = (0, state_1.parseClickOptions)(table);
195
174
  const element = page.getByText(text).first();
196
175
  await element.dblclick(options);
197
176
  console.log(`🖱️ Double-clicked on text "${text}"`);
198
- });
177
+ }
199
178
  /**
200
179
  * Double-clicks at specific X, Y coordinates on the page.
201
- *
202
- * ```gherkin
203
- * When I double click position {int} {int}
204
- * ```
180
+ * @example
181
+ * When I double click position 100 200
205
182
  */
206
- exports.DoubleClickPosition = (0, registry_1.Step)("I double click position {int} {int}", async (page, x, y, table) => {
183
+ async function doubleClickPosition(page, x, y, table) {
207
184
  const options = (0, state_1.parseClickOptions)(table);
208
185
  await page.mouse.dblclick(x, y, options);
209
186
  console.log(`🖱️ Double-clicked at (${x}, ${y})`);
210
- });
187
+ }
211
188
  /**
212
189
  * Right-clicks (Context Click) on the currently stored element.
213
- *
214
- * ```gherkin
190
+ * @example
215
191
  * When I right click
216
- * ```
217
192
  */
218
- exports.RightClickStoredElement = (0, registry_1.Step)("I right click", async (page, table) => {
193
+ async function rightClickStoredElement(page, table) {
219
194
  const options = (0, state_1.parseClickOptions)(table);
220
195
  const element = (0, state_1.getActiveElement)(page);
221
196
  await element.click({ button: "right", ...options });
222
197
  console.log("🖱️ Right-clicked on stored element");
223
- });
198
+ }
224
199
  /**
225
200
  * Right-clicks on the first element containing the specified text.
226
- *
227
- * ```gherkin
228
- * When I right click on text {string}
229
- * ```
201
+ * @example
202
+ * When I right click on text "Menu"
230
203
  */
231
- exports.RightClickByText = (0, registry_1.Step)("I right click on text {string}", async (page, text, table) => {
204
+ async function rightClickByText(page, text, table) {
232
205
  const options = (0, state_1.parseClickOptions)(table);
233
206
  const element = page.getByText(text).first();
234
207
  await element.click({ button: "right", ...options });
235
208
  console.log(`🖱️ Right-clicked on text "${text}"`);
236
- });
209
+ }
237
210
  /**
238
211
  * Right-clicks at specific X, Y coordinates on the page.
239
- *
240
- * ```gherkin
241
- * When I right click position {int} {int}
242
- * ```
212
+ * @example
213
+ * When I right click position 100 200
243
214
  */
244
- exports.RightClickPosition = (0, registry_1.Step)("I right click position {int} {int}", async (page, x, y, table) => {
215
+ async function rightClickPosition(page, x, y, table) {
245
216
  const options = (0, state_1.parseClickOptions)(table);
246
217
  await page.mouse.click(x, y, { button: "right", ...options });
247
218
  console.log(`🖱️ Right-clicked at (${x}, ${y})`);
248
- });
219
+ }
220
+ /**
221
+ * Clicks on the Nth element containing the specified text.
222
+ * Handles 1st, 2nd, 3rd, 4th, etc.
223
+ * @example
224
+ * When I click on 1st element "Login"
225
+ * When I click on 2nd element "Submit"
226
+ */
227
+ async function clickNthElementByText(page, indexStr, text, table) {
228
+ const index = parseInt(indexStr, 10);
229
+ const options = (0, state_1.parseClickOptions)(table);
230
+ // Playwright nth is 0-indexed
231
+ const locator = page.getByText(text, { exact: false }).nth(index - 1);
232
+ await locator.waitFor({ state: "visible", timeout: options.timeout || 5000 });
233
+ await locator.click(options);
234
+ (0, state_1.setActiveElement)(page, locator);
235
+ console.log(`🖱️ Clicked on ${indexStr} element with text "${text}"`);
236
+ }
237
+ /**
238
+ * Clicks on the Nth element matching a CSS or XPath selector.
239
+ * @example
240
+ * When I click on 1st selector ".btn"
241
+ */
242
+ async function clickNthElementBySelector(page, indexStr, selector, table) {
243
+ const index = parseInt(indexStr, 10);
244
+ const options = (0, state_1.parseClickOptions)(table);
245
+ const locator = page.locator(selector).nth(index - 1);
246
+ await locator.waitFor({ state: "visible", timeout: options.timeout || 5000 });
247
+ await locator.click(options);
248
+ (0, state_1.setActiveElement)(page, locator);
249
+ console.log(`🖱️ Clicked on ${indexStr} selector "${selector}"`);
250
+ }
251
+ // ==================================================
252
+ // GLUE STEPS
253
+ // ==================================================
254
+ (0, registry_1.Step)("I click", clickStoredElement);
255
+ (0, registry_1.Step)("I click on element {string}", clickElementBySelector);
256
+ (0, registry_1.Step)("I click on button {string}", clickButtonByLabel);
257
+ (0, registry_1.Step)("I click on link {string}", clickLinkByText);
258
+ (0, registry_1.Step)("I click on label {string}", clickLabelByText);
259
+ (0, registry_1.Step)("I click on text {string}", clickByText);
260
+ (0, registry_1.Step)("I click on exact text {string}", clickByExactText);
261
+ (0, registry_1.Step)(/^I click on selector "([^"]+)"$/, clickByRegexSelector);
262
+ (0, registry_1.Step)("I click all", clickAllStoredElements);
263
+ (0, registry_1.Step)("I double click", doubleClickStoredElement);
264
+ (0, registry_1.Step)("I double click on text {string}", doubleClickByText);
265
+ (0, registry_1.Step)("I double click position {int} {int}", doubleClickPosition);
266
+ (0, registry_1.Step)("I right click", rightClickStoredElement);
267
+ (0, registry_1.Step)("I right click on text {string}", rightClickByText);
268
+ (0, registry_1.Step)("I right click position {int} {int}", rightClickPosition);
269
+ (0, registry_1.Step)(/^I click on (\d+)(?:st|nd|rd|th) element "([^"]+)"$/, clickNthElementByText);
270
+ (0, registry_1.Step)(/^I click on (\d+)(?:st|nd|rd|th) selector "([^"]+)"$/, clickNthElementBySelector);