webship-js 2.0.1 → 2.0.3

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 (194) hide show
  1. package/AGENTS.md +109 -0
  2. package/CLAUDE.md +317 -0
  3. package/bin/generate-reports.js +363 -0
  4. package/bin/init-webship.js +343 -0
  5. package/bin/postinstall.js +8 -74
  6. package/cucumber.js +66 -2
  7. package/docs/00-quick-start.md +102 -0
  8. package/docs/01-getting-started.md +102 -0
  9. package/docs/02-bbr-smart-waits.md +77 -0
  10. package/docs/03-selector-registry.md +95 -0
  11. package/docs/04-step-reference.md +728 -0
  12. package/docs/05-web-first-assertions.md +91 -0
  13. package/docs/06-network-and-dialogs.md +83 -0
  14. package/docs/07-auth-state.md +75 -0
  15. package/docs/08-clock-mocking.md +59 -0
  16. package/docs/09-api-testing.md +114 -0
  17. package/docs/10-accessibility.md +167 -0
  18. package/docs/11-debugging.md +129 -0
  19. package/docs/12-ai-agent-guide.md +338 -0
  20. package/docs/13-faq.md +236 -0
  21. package/docs/14-recipes-cookbook.md +255 -0
  22. package/docs/15-tag-conventions.md +76 -0
  23. package/docs/advanced-screenshots/then-i-save-fullscreen-screenshot.md +36 -0
  24. package/docs/advanced-screenshots/then-i-save-width-x-height-screenshot.md +34 -0
  25. package/docs/advanced-screenshots/when-i-save-screenshot-name-filename.md +45 -0
  26. package/docs/advanced-screenshots.md +52 -0
  27. package/docs/advanced-selectors.md +18 -0
  28. package/docs/api-step-definitions.md +45 -0
  29. package/docs/diffy-step-definitions/then-compare-diffy-env1-env2.md +30 -0
  30. package/docs/diffy-step-definitions/then-create-diffy-comparison-name-value.md +21 -0
  31. package/docs/diffy-step-definitions/then-create-diffy-comparison.md +25 -0
  32. package/docs/diffy-step-definitions/then-create-diffy-screenshot-environment-name.md +35 -0
  33. package/docs/diffy-step-definitions/then-i-take-screenshot.md +21 -0
  34. package/docs/diffy-step-definitions/then-i-take-screenshots-all-breakpoints.md +27 -0
  35. package/docs/diffy-step-definitions/then-send-screenshots-diffy-name-value.md +27 -0
  36. package/docs/diffy-step-definitions/then-upload-folder-url-diffy-snapshotname.md +28 -0
  37. package/docs/diffy-step-definitions/then-wait-diffy-comparison-complete.md +21 -0
  38. package/docs/diffy-step-definitions/when-i-resize-window-number.md +29 -0
  39. package/docs/diffy-step-definitions.md +21 -0
  40. package/docs/global-settings.md +244 -0
  41. package/docs/index.md +104 -0
  42. package/docs/install-webship-js/ddev-webship-js.md +52 -0
  43. package/docs/install-webship-js.md +35 -0
  44. package/docs/overview.md +41 -0
  45. package/docs/step-definitions/given-i-am-anonymous-user.md +67 -0
  46. package/docs/step-definitions/given-i-am-homepage.md +68 -0
  47. package/docs/step-definitions/given-i-am-specific-page.md +72 -0
  48. package/docs/step-definitions/then-i-should-be.md +56 -0
  49. package/docs/step-definitions/then-i-should-see.md +62 -0
  50. package/docs/step-definitions/then-item-checkbox.md +54 -0
  51. package/docs/step-definitions/then-item-link-should-contain-url.md +84 -0
  52. package/docs/step-definitions/then-item-should-contain.md +67 -0
  53. package/docs/step-definitions/then-radio-button-value-should-be-selected.md +68 -0
  54. package/docs/step-definitions/then-response-status-code-should-be-number.md +69 -0
  55. package/docs/step-definitions/then-value-radio-button-selected.md +62 -0
  56. package/docs/step-definitions/when-i-attach-file-file-name-element.md +71 -0
  57. package/docs/step-definitions/when-i-check-checkbox.md +60 -0
  58. package/docs/step-definitions/when-i-click-link.md +51 -0
  59. package/docs/step-definitions/when-i-click-operation-text-row.md +71 -0
  60. package/docs/step-definitions/when-i-fill.md +59 -0
  61. package/docs/step-definitions/when-i-go-homepage.md +60 -0
  62. package/docs/step-definitions/when-i-go-specific-page.md +67 -0
  63. package/docs/step-definitions/when-i-move-backward-one-page.md +49 -0
  64. package/docs/step-definitions/when-i-move-forward-one-page.md +58 -0
  65. package/docs/step-definitions/when-i-press-button.md +58 -0
  66. package/docs/step-definitions/when-i-reload-page.md +51 -0
  67. package/docs/step-definitions/when-i-scroll.md +73 -0
  68. package/docs/step-definitions/when-i-select-option-select-list.md +53 -0
  69. package/docs/step-definitions/when-i-select-radio-button-value.md +62 -0
  70. package/docs/step-definitions/when-i-uncheck-checkbox.md +57 -0
  71. package/docs/step-definitions/when-i-wait-ajax-finish.md +64 -0
  72. package/docs/step-definitions/when-i-wait.md +62 -0
  73. package/docs/step-definitions.md +50 -0
  74. package/examples/a11y.html +31 -0
  75. package/examples/cookies.html +10 -0
  76. package/examples/date.html +12 -0
  77. package/examples/diffy/baseline.html +54 -0
  78. package/examples/diffy/changed.html +63 -0
  79. package/examples/diffy/index.html +52 -0
  80. package/examples/element.html +11 -0
  81. package/examples/field.html +24 -0
  82. package/examples/index.html +6 -0
  83. package/examples/keyboard.html +11 -0
  84. package/examples/links.html +9 -0
  85. package/examples/modal.html +14 -0
  86. package/examples/path.html +3 -0
  87. package/examples/table.html +13 -0
  88. package/examples/test--when--i-additionally-select.html +27 -0
  89. package/package.json +19 -6
  90. package/playwright.config.ts +3 -2
  91. package/tests/features/a11y.feature +39 -0
  92. package/tests/features/cookie.feature +13 -0
  93. package/tests/features/date.feature +11 -0
  94. package/tests/features/diffy/test--diffy-01-example-demo.feature +22 -0
  95. package/tests/features/diffy/test--diffy-02-all-steps.feature +52 -0
  96. package/tests/features/diffy/test--diffy-03-real-api.feature +21 -0
  97. package/tests/features/element.feature +16 -0
  98. package/tests/features/field.feature +25 -0
  99. package/tests/features/keyboard.feature +10 -0
  100. package/tests/features/link.feature +11 -0
  101. package/tests/features/modal-advanced-example.feature +1 -1
  102. package/tests/features/modal.feature +11 -0
  103. package/tests/features/path.feature +16 -0
  104. package/tests/features/response.feature +8 -0
  105. package/tests/features/responsive.feature +10 -0
  106. package/tests/features/table.feature +18 -0
  107. package/tests/features/test--then--i-save-screenshot.feature +33 -0
  108. package/tests/features/test--then--i-see-locator.feature +320 -0
  109. package/tests/features/test--then--i-should-see-n-elements.feature +24 -0
  110. package/tests/features/test--then--print-current-url-and-response.feature +21 -0
  111. package/tests/features/test--when--i-additionally-select.feature +30 -0
  112. package/tests/features/test--when--i-follow.feature +22 -0
  113. package/tests/features/wait.feature +7 -0
  114. package/tests/features/yaml.feature +102 -0
  115. package/tests/reports/README.md +55 -0
  116. package/tests/selectors/_canonical-keys.json +113 -0
  117. package/tests/selectors/back-end-selectors.json +19 -0
  118. package/tests/selectors/cms-contentful-admin.json +35 -0
  119. package/tests/selectors/cms-craft-admin.json +39 -0
  120. package/tests/selectors/cms-drupal-cms-gin.json +56 -0
  121. package/tests/selectors/cms-drupal-core-claro.json +50 -0
  122. package/tests/selectors/cms-generic-admin.json +34 -0
  123. package/tests/selectors/cms-ghost-admin.json +34 -0
  124. package/tests/selectors/cms-joomla-admin.json +41 -0
  125. package/tests/selectors/cms-magento2-admin.json +32 -0
  126. package/tests/selectors/cms-prestashop-admin.json +38 -0
  127. package/tests/selectors/cms-shopify-admin.json +25 -0
  128. package/tests/selectors/cms-strapi-admin.json +42 -0
  129. package/tests/selectors/cms-typo3-admin.json +41 -0
  130. package/tests/selectors/cms-woocommerce-front.json +50 -0
  131. package/tests/selectors/cms-wordpress-admin.json +31 -0
  132. package/tests/selectors/framework-ant-design.json +80 -0
  133. package/tests/selectors/framework-bootstrap.json +86 -0
  134. package/tests/selectors/framework-bulma.json +74 -0
  135. package/tests/selectors/framework-chakra.json +58 -0
  136. package/tests/selectors/framework-foundation.json +51 -0
  137. package/tests/selectors/framework-material-ui.json +72 -0
  138. package/tests/selectors/framework-shadcn.json +51 -0
  139. package/tests/selectors/framework-tailwind.json +40 -0
  140. package/tests/selectors/framework-vuetify.json +61 -0
  141. package/tests/selectors/front-end-selectors.json +16 -0
  142. package/tests/selectors/homepage-selectors.json +13 -0
  143. package/tests/step-definitions/a11y.steps.js +798 -0
  144. package/tests/step-definitions/action.steps.js +167 -0
  145. package/tests/step-definitions/{webship-api.js → api.steps.js} +254 -44
  146. package/tests/step-definitions/assertion.steps.js +352 -0
  147. package/tests/step-definitions/auth.steps.js +124 -0
  148. package/tests/step-definitions/clock.steps.js +128 -0
  149. package/tests/step-definitions/cookie.steps.js +216 -0
  150. package/tests/step-definitions/debug.steps.js +31 -0
  151. package/tests/step-definitions/dialog.steps.js +193 -0
  152. package/tests/step-definitions/element.steps.js +314 -0
  153. package/tests/step-definitions/field.steps.js +653 -0
  154. package/tests/step-definitions/file-download.steps.js +193 -0
  155. package/tests/step-definitions/form.steps.js +333 -0
  156. package/tests/step-definitions/iframe.steps.js +178 -0
  157. package/tests/step-definitions/input.steps.js +163 -0
  158. package/tests/step-definitions/javascript.steps.js +71 -0
  159. package/tests/step-definitions/keyboard.steps.js +78 -0
  160. package/tests/step-definitions/link.steps.js +142 -0
  161. package/tests/step-definitions/metatag.steps.js +91 -0
  162. package/tests/step-definitions/modal.steps.js +219 -0
  163. package/tests/step-definitions/navigation.steps.js +218 -0
  164. package/tests/step-definitions/network.steps.js +238 -0
  165. package/tests/step-definitions/path.steps.js +141 -0
  166. package/tests/step-definitions/response.steps.js +98 -0
  167. package/tests/step-definitions/responsive.steps.js +123 -0
  168. package/tests/step-definitions/rest.steps.js +111 -0
  169. package/tests/step-definitions/screenshot.steps.js +423 -0
  170. package/tests/step-definitions/scroll.steps.js +189 -0
  171. package/tests/step-definitions/selectors.steps.js +996 -0
  172. package/tests/step-definitions/storage.steps.js +194 -0
  173. package/tests/step-definitions/table.steps.js +181 -0
  174. package/tests/step-definitions/wait.steps.js +400 -0
  175. package/tests/step-definitions/web-first.steps.js +296 -0
  176. package/tests/step-definitions/webship.js +567 -923
  177. package/tests/step-definitions/xml.steps.js +409 -0
  178. package/tests/step-definitions/yaml.steps.js +911 -0
  179. package/tests/step-definitions-diffy/README.md +329 -0
  180. package/tests/step-definitions-diffy/mock-diffy-api/server.js +84 -0
  181. package/tests/step-definitions-diffy/webship-diffy-mock.js +31 -0
  182. package/tests/step-definitions-diffy/webship-diffy.js +459 -0
  183. package/tsconfig.json +19 -3
  184. package/generate-reports.js +0 -22
  185. package/required/cucumber.js +0 -37
  186. package/required/generate-reports.js +0 -22
  187. package/required/package.json +0 -18
  188. package/required/playwright.config.ts +0 -37
  189. package/required/tests/features/README.md +0 -1
  190. package/required/tests/features/check-homepage.feature +0 -8
  191. package/required/tests/reports/README.md +0 -1
  192. package/required/tests/step-definitions/README.md +0 -1
  193. package/required/tests/step-definitions/custom.js +0 -4
  194. package/required/tsconfig.json +0 -12
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ // Iframe / frame steps backed by Playwright's `frameLocator` API.
4
+ //
5
+ // Frames are addressed by CSS selector. Once switched, frame-scoped
6
+ // interaction steps target the chosen frame instead of the main document.
7
+ // Switch back with "I switch to the root document".
8
+
9
+ const { When, Then } = require('@cucumber/cucumber');
10
+ const assert = require('assert');
11
+
12
+ function frameRoot(world) {
13
+ return world.frame || world.page;
14
+ }
15
+
16
+ /**
17
+ * Switch the active scope to an iframe addressed by CSS selector.
18
+ *
19
+ * Example #1: When I switch to iframe "iframe.payment"
20
+ * Example #2: When I switch to the iframe "#stripe-frame"
21
+ * Example #3: And we switch to iframe "iframe[name=widget]"
22
+ * Example #4: When I switch to iframe ".captcha-frame"
23
+ * Example #5: When I switch to the iframe "iframe[src*=embed]"
24
+ *
25
+ */
26
+ When(/^(I |we )*switch to (the )?iframe "([^"]*)"$/, async function (pronoun, theCase, sel) {
27
+ if (!this._rootPage) this._rootPage = this.page;
28
+ this.frame = this.page.frameLocator(sel);
29
+ });
30
+
31
+ /**
32
+ * Switch the active scope to an iframe by Playwright frame-locator string.
33
+ *
34
+ * Example #1: When I switch to iframe with locator "iframe.payment"
35
+ * Example #2: When I switch to iframe with locator "#stripe-frame"
36
+ * Example #3: And I switch to iframe with locator "iframe[name=widget]"
37
+ * Example #4: When I switch to iframe with locator ".captcha-frame"
38
+ * Example #5: When I switch to iframe with locator "iframe[src*=embed]"
39
+ *
40
+ */
41
+ When(/^(I |we )*switch to iframe with locator "([^"]*)"$/, async function (pronoun, sel) {
42
+ if (!this._rootPage) this._rootPage = this.page;
43
+ this.frame = this.page.frameLocator(sel);
44
+ });
45
+
46
+ /**
47
+ * Return the active scope to the top document (clear the iframe scope).
48
+ *
49
+ * Example #1: When I switch to the root document
50
+ * Example #2: When I switch to iframe ".captcha"
51
+ * And I click "I am not a robot" inside the iframe
52
+ * And I switch to the root document
53
+ * Example #3: And we switch to the root document
54
+ * Example #4: When I switch to iframe "#payment"
55
+ * And I press "Pay"
56
+ * And I switch to the root document
57
+ * Then I should see "Payment received"
58
+ * Example #5: When I switch to the root document
59
+ * And I press "Refresh"
60
+ *
61
+ */
62
+ When(/^(I |we )*switch to the root document$/, async function () {
63
+ this.frame = null;
64
+ });
65
+
66
+ /**
67
+ * Switch the active scope to an iframe by its `title` attribute.
68
+ *
69
+ * Example #1: When I switch to the iframe with title "Payment"
70
+ * Example #2: When I switch to the iframe with title "Captcha"
71
+ * Example #3: And we switch to the iframe with title "Widget"
72
+ * Example #4: When I switch to the iframe with title "Embedded video"
73
+ * Example #5: When I switch to the iframe with title "Stripe checkout"
74
+ *
75
+ */
76
+ When(/^(I |we )*switch to the iframe with title "([^"]*)"$/, async function (pronoun, title) {
77
+ if (!this._rootPage) this._rootPage = this.page;
78
+ this.frame = this.page.frameLocator(`iframe[title="${title}"]`);
79
+ });
80
+
81
+ /**
82
+ * Switch the active scope to an iframe by its `name` attribute.
83
+ *
84
+ * Example #1: When I switch to the iframe with name "payment"
85
+ * Example #2: When I switch to the iframe with name "captcha"
86
+ * Example #3: And we switch to the iframe with name "widget"
87
+ * Example #4: When I switch to the iframe with name "embed"
88
+ * Example #5: When I switch to the iframe with name "stripe"
89
+ *
90
+ */
91
+ When(/^(I |we )*switch to the iframe with name "([^"]*)"$/, async function (pronoun, name) {
92
+ if (!this._rootPage) this._rootPage = this.page;
93
+ this.frame = this.page.frameLocator(`iframe[name="${name}"]`);
94
+ });
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Frame-scoped click + fill + assertions
98
+ // ---------------------------------------------------------------------------
99
+
100
+ /**
101
+ * Click visible text inside the active iframe.
102
+ *
103
+ * Example #1: When I click "Confirm" inside the iframe
104
+ * Example #2: When I click "Cancel" inside the iframe
105
+ * Example #3: And we click "Continue" inside the iframe
106
+ * Example #4: When I click "OK" inside the iframe
107
+ * Example #5: When I click "Close" inside the iframe
108
+ *
109
+ */
110
+ When(/^(I |we )*click "([^"]*)" inside the iframe$/, async function (pronoun, text) {
111
+ const root = frameRoot(this);
112
+ if (!root.locator) throw new Error('No active iframe. Switch first.');
113
+ await root.locator(`text="${text}"`).first().click();
114
+ });
115
+
116
+ /**
117
+ * Click an attribute-addressed element inside the active iframe.
118
+ *
119
+ * Tries id, class, name, and data-testid in that order.
120
+ *
121
+ * Example #1: When I click "submit-btn" by attr inside the iframe
122
+ * Example #2: When I click "cancel" by attr inside the iframe
123
+ * Example #3: And we click "continue" by attr inside the iframe
124
+ * Example #4: When I click "close" by attr inside the iframe
125
+ * Example #5: When I click "primary-cta" by attr inside the iframe
126
+ *
127
+ */
128
+ When(/^(I |we )*click "([^"]*)" by attr inside the iframe$/, async function (pronoun, attrValue) {
129
+ const root = frameRoot(this);
130
+ await root.locator(`#${attrValue}, .${attrValue}, [name="${attrValue}"], [data-testid="${attrValue}"]`).first().click();
131
+ });
132
+
133
+ /**
134
+ * Fill a field inside the active iframe by `[name]` or id.
135
+ *
136
+ * Example #1: When I fill in "card_number" with "4242 4242 4242 4242" inside the iframe
137
+ * Example #2: When I fill in "cvv" with "123" inside the iframe
138
+ * Example #3: And we fill in "exp_date" with "12/30" inside the iframe
139
+ * Example #4: When I fill in "email" with "alice@example.com" inside the iframe
140
+ * Example #5: When I fill in "name" with "Alice" inside the iframe
141
+ *
142
+ */
143
+ When(/^(I |we )*fill in "([^"]*)" with "([^"]*)" inside the iframe$/, async function (pronoun, field, value) {
144
+ const root = frameRoot(this);
145
+ await root.locator(`[name="${field}"], #${field}`).first().fill(value);
146
+ });
147
+
148
+ /**
149
+ * Assert visible text exists inside the active iframe.
150
+ *
151
+ * Example #1: Then I should see "Payment received" inside the iframe
152
+ * Example #2: Then I should see "Welcome" inside the iframe
153
+ * Example #3: And I should see "Confirmed" inside the iframe
154
+ * Example #4: Then I should see "Email verified" inside the iframe
155
+ * Example #5: Then I should see "Subscribed" inside the iframe
156
+ *
157
+ */
158
+ Then(/^I should see "([^"]*)" inside the iframe$/, async function (text) {
159
+ const root = frameRoot(this);
160
+ const count = await root.locator(`text="${text}"`).count();
161
+ assert.ok(count > 0, `Expected to see "${text}" inside the iframe.`);
162
+ });
163
+
164
+ /**
165
+ * Assert visible text does NOT exist inside the active iframe.
166
+ *
167
+ * Example #1: Then I should not see "Error" inside the iframe
168
+ * Example #2: Then I should not see "Declined" inside the iframe
169
+ * Example #3: And I should not see "Loading" inside the iframe
170
+ * Example #4: Then I should not see "Pending" inside the iframe
171
+ * Example #5: Then I should not see "Try again" inside the iframe
172
+ *
173
+ */
174
+ Then(/^I should not see "([^"]*)" inside the iframe$/, async function (text) {
175
+ const root = frameRoot(this);
176
+ const count = await root.locator(`text="${text}"`).count();
177
+ assert.strictEqual(count, 0, `Expected NOT to see "${text}" inside the iframe.`);
178
+ });
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ // Pointer input steps not covered by the core element/click steps:
4
+ // hover variants, drag-and-drop, double-click, right-click, viewport size.
5
+
6
+ const { When } = require('@cucumber/cucumber');
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // Hover (variants)
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /**
13
+ * Hover the mouse pointer over a CSS-addressed element.
14
+ *
15
+ * Example #1: When I hover over "#nav-products"
16
+ * Example #2: When I hover over ".tooltip-trigger"
17
+ * Example #3: And we hover over "[data-testid=user-menu]"
18
+ * Example #4: When I hover over "button.help"
19
+ * Example #5: When I hover over ".chart-bar:nth-child(3)"
20
+ *
21
+ */
22
+ When(/^(I |we )*hover over "([^"]*)"$/, async function (pronoun, sel) {
23
+ await this.page.locator(sel).first().hover();
24
+ });
25
+
26
+ /**
27
+ * Move the mouse pointer over a CSS-addressed element (alias for hover).
28
+ *
29
+ * Example #1: When I move the pointer to "#cta"
30
+ * Example #2: When we move the pointer to ".dropdown-trigger"
31
+ * Example #3: And I move the pointer to "[data-testid=avatar]"
32
+ * Example #4: When I move the pointer to "img.gallery-thumb"
33
+ * Example #5: When I move the pointer to ".legend-item"
34
+ *
35
+ */
36
+ When(/^(I |we )*move the pointer to "([^"]*)"$/, async function (pronoun, sel) {
37
+ await this.page.locator(sel).first().hover();
38
+ });
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Click variants
42
+ // ---------------------------------------------------------------------------
43
+
44
+ /**
45
+ * Double-click on a CSS-addressed element.
46
+ *
47
+ * Example #1: When I double-click on "#row-1"
48
+ * Example #2: When I double click on ".file-tile"
49
+ * Example #3: And we double-click on "[data-testid=cell-A1]"
50
+ * Example #4: When I double-click on "img.editable"
51
+ * Example #5: When I double click on "td.editable-cell"
52
+ *
53
+ */
54
+ When(/^(I |we )*double[- ]click on "([^"]*)"$/, async function (pronoun, sel) {
55
+ await this.page.locator(sel).first().dblclick();
56
+ });
57
+
58
+ /**
59
+ * Right-click (context menu) on a CSS-addressed element.
60
+ *
61
+ * Example #1: When I right-click on "#row-1"
62
+ * Example #2: When I right click on ".tree-node"
63
+ * Example #3: And we right-click on "[data-testid=image]"
64
+ * Example #4: When I right-click on "li.contact"
65
+ * Example #5: When I right click on "td.cell"
66
+ *
67
+ */
68
+ When(/^(I |we )*right[- ]click on "([^"]*)"$/, async function (pronoun, sel) {
69
+ await this.page.locator(sel).first().click({ button: 'right' });
70
+ });
71
+
72
+ /**
73
+ * Middle-click on a CSS-addressed element.
74
+ *
75
+ * Example #1: When I middle-click on "a.external"
76
+ * Example #2: When I middle click on "#tab-2"
77
+ * Example #3: And we middle-click on "[data-testid=link]"
78
+ * Example #4: When I middle-click on "li.bookmark"
79
+ * Example #5: When I middle click on "a.product-link"
80
+ *
81
+ */
82
+ When(/^(I |we )*middle[- ]click on "([^"]*)"$/, async function (pronoun, sel) {
83
+ await this.page.locator(sel).first().click({ button: 'middle' });
84
+ });
85
+
86
+ /**
87
+ * Click on a CSS-addressed element while holding a modifier key.
88
+ *
89
+ * Modifier names follow Playwright: `Shift`, `Control`, `Alt`, `Meta`.
90
+ *
91
+ * Example #1: When I click on "#row-1" while holding "Shift"
92
+ * Example #2: When I click on ".checkbox" while holding "Control"
93
+ * Example #3: And we click on "a.external" while holding "Meta"
94
+ * Example #4: When I click on ".item" while holding "Alt"
95
+ * Example #5: When I click on "#tab-2" while holding "Shift"
96
+ *
97
+ */
98
+ When(/^(I |we )*click on "([^"]*)" while holding "([^"]*)"$/, async function (pronoun, sel, key) {
99
+ await this.page.locator(sel).first().click({ modifiers: [key] });
100
+ });
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // Drag and drop
104
+ // ---------------------------------------------------------------------------
105
+
106
+ /**
107
+ * Drag a source element onto a target element.
108
+ *
109
+ * Example #1: When I drag "#card-1" to "#column-done"
110
+ * Example #2: When I drag ".file-tile" to "#trash"
111
+ * Example #3: And we drag "[data-testid=task-1]" to "[data-testid=in-progress]"
112
+ * Example #4: When I drag "#image" to "#canvas"
113
+ * Example #5: When I drag "li.draggable" to "ul.dropzone"
114
+ *
115
+ */
116
+ When(/^(I |we )*drag "([^"]*)" to "([^"]*)"$/, async function (pronoun, source, target) {
117
+ await this.page.locator(source).first().dragTo(this.page.locator(target).first());
118
+ });
119
+
120
+ // ---------------------------------------------------------------------------
121
+ // Viewport
122
+ // ---------------------------------------------------------------------------
123
+
124
+ /**
125
+ * Resize the browser viewport to a specific WxH.
126
+ *
127
+ * Example #1: When I set the viewport size to 1280x720
128
+ * Example #2: When I set the viewport size to 375x667
129
+ * Example #3: And we set the viewport size to 768x1024
130
+ * Example #4: When I set the viewport size to 1920x1080
131
+ * Example #5: When I set the viewport size to 320x568
132
+ *
133
+ */
134
+ When(/^(I |we )*set the viewport size to (\d+)x(\d+)$/, async function (pronoun, w, h) {
135
+ await this.page.setViewportSize({ width: parseInt(w, 10), height: parseInt(h, 10) });
136
+ });
137
+
138
+ // ---------------------------------------------------------------------------
139
+ // Tap (touch)
140
+ // ---------------------------------------------------------------------------
141
+
142
+ /**
143
+ * Touch-tap a CSS-addressed element. Falls back to a regular click if the
144
+ * browser context was not opened with `hasTouch: true`.
145
+ *
146
+ * Example #1: When I tap on "#cta"
147
+ * Example #2: When I tap on ".bottom-nav-item"
148
+ * Example #3: And we tap on "[data-testid=fab]"
149
+ * Example #4: When I tap on "button.menu"
150
+ * Example #5: When I tap on ".swipe-card"
151
+ *
152
+ */
153
+ When(/^(I |we )*tap on "([^"]*)"$/, async function (pronoun, sel) {
154
+ try {
155
+ await this.page.locator(sel).first().tap();
156
+ } catch (e) {
157
+ if (/hasTouch/i.test(e.message)) {
158
+ await this.page.locator(sel).first().click();
159
+ } else {
160
+ throw e;
161
+ }
162
+ }
163
+ });
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ // Auto-detect JavaScript errors during test execution.
4
+ //
5
+ // Errors collected from page.on('pageerror') and page.on('console') (level=error).
6
+ // Always tracked once a page is opened. Final assertion runs only when:
7
+ // - the scenario is tagged @javascript (asserts no errors at scenario end), OR
8
+ // - the test explicitly calls "Then there should be no JavaScript errors".
9
+ // Use the @js-errors tag to suppress the @javascript assertion when errors
10
+ // are intentionally expected.
11
+
12
+ const { Before, After, Then } = require('@cucumber/cucumber');
13
+ const assert = require('assert');
14
+
15
+ function hasTag(scenario, name) {
16
+ if (!scenario || !Array.isArray(scenario.pickle && scenario.pickle.tags)) return false;
17
+ return scenario.pickle.tags.some((t) => t.name === name);
18
+ }
19
+
20
+ Before({ order: 200 }, function (scope) {
21
+ this._jsErrors = [];
22
+ this._jsErrorsAsserted = false;
23
+ this._jsErrorsAutoAssert = hasTag(scope, '@javascript');
24
+ if (!this.page) return;
25
+ this.page.on('pageerror', (err) => {
26
+ this._jsErrors.push({ type: 'pageerror', message: String(err && err.message || err) });
27
+ });
28
+ this.page.on('console', (msg) => {
29
+ if (msg.type() === 'error') {
30
+ this._jsErrors.push({ type: 'console.error', message: msg.text() });
31
+ }
32
+ });
33
+ });
34
+
35
+ /**
36
+ * Assert that no JavaScript errors have been collected so far.
37
+ *
38
+ * Errors are tracked from page open (page errors + console.error). Calling
39
+ * this step asserts the error log is empty and prevents the auto-assert at
40
+ * scenario end (so it does not double-fire).
41
+ *
42
+ * Example #1: Then there should be no JavaScript errors
43
+ * Example #2: Given I am on the homepage
44
+ * Then there should be no JavaScript errors
45
+ * Example #3: When I follow "Pricing"
46
+ * And I wait until the network is idle
47
+ * Then there should be no JavaScript errors
48
+ * Example #4: When I press "Add to cart"
49
+ * Then there should be no JavaScript errors
50
+ * Example #5: Given I am on "/dashboard"
51
+ * And I scroll to the bottom
52
+ * Then there should be no JavaScript errors
53
+ *
54
+ */
55
+ Then(/^there should be no JavaScript errors$/, function () {
56
+ this._jsErrorsAsserted = true;
57
+ const errs = this._jsErrors || [];
58
+ if (errs.length === 0) return;
59
+ const summary = errs.map((e, i) => ` ${i + 1}. [${e.type}] ${e.message}`).join('\n');
60
+ assert.fail(`JavaScript errors detected:\n${summary}`);
61
+ });
62
+
63
+ After({ order: 200 }, function (scope) {
64
+ if (!this._jsErrorsAutoAssert) return;
65
+ if (hasTag(scope, '@js-errors')) return;
66
+ if (this._jsErrorsAsserted) return;
67
+ const errs = this._jsErrors || [];
68
+ if (errs.length === 0) return;
69
+ const summary = errs.map((e, i) => ` ${i + 1}. [${e.type}] ${e.message}`).join('\n');
70
+ assert.fail(`JavaScript errors detected during scenario:\n${summary}`);
71
+ });
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ // Simulate keyboard interactions on the page or on a specific element.
4
+
5
+ const { When } = require('@cucumber/cucumber');
6
+
7
+ // Common name aliases — lowercase names like "enter", "tab".
8
+ function normalizeKey(key) {
9
+ const map = {
10
+ enter: 'Enter', return: 'Enter', tab: 'Tab', escape: 'Escape', esc: 'Escape',
11
+ space: 'Space', backspace: 'Backspace', delete: 'Delete',
12
+ up: 'ArrowUp', down: 'ArrowDown', left: 'ArrowLeft', right: 'ArrowRight',
13
+ home: 'Home', end: 'End', pageup: 'PageUp', pagedown: 'PageDown',
14
+ };
15
+ const lower = key.toLowerCase();
16
+ return map[lower] || key;
17
+ }
18
+
19
+ /**
20
+ * Press a single key against the page (whatever element is currently focused).
21
+ *
22
+ * Common aliases (`enter`, `tab`, `esc`, `space`, `up/down/left/right`) are
23
+ * normalised to Playwright's canonical key names.
24
+ *
25
+ * Example #1: When I press the key "Enter"
26
+ * Example #2: When I press the key "Escape"
27
+ * Example #3: And I press the key "Tab"
28
+ * Example #4: When I press the key "ArrowDown"
29
+ * Example #5: When I focus on the element "#search"
30
+ * And I press the key "Enter"
31
+ *
32
+ */
33
+ When(/^(I |we )*press the key "([^"]*)"$/, async function (pronoun, key) {
34
+ await this.page.keyboard.press(normalizeKey(key));
35
+ });
36
+
37
+ /**
38
+ * Press a single key while a specific element is focused.
39
+ *
40
+ * Example #1: When I press the key "Enter" on the element "#search"
41
+ * Example #2: When I press the key "Tab" on the element "input[type=email]"
42
+ * Example #3: And I press the key "ArrowDown" on the element ".combobox"
43
+ * Example #4: When I press the key "Backspace" on the element "#name"
44
+ * Example #5: When I press the key "Escape" on the element "[role=dialog]"
45
+ *
46
+ */
47
+ When(/^(I |we )*press the key "([^"]*)" on the element "([^"]*)"$/, async function (pronoun, key, sel) {
48
+ await this.page.locator(sel).first().press(normalizeKey(key));
49
+ });
50
+
51
+ /**
52
+ * Press a key combination against the page. Combos use `+` between modifiers
53
+ * and the final key (e.g. `Control+a`, `Meta+s`, `Shift+Tab`).
54
+ *
55
+ * Example #1: When I press the keys "Control+a"
56
+ * Example #2: When I press the keys "Meta+s"
57
+ * Example #3: And I press the keys "Shift+Tab"
58
+ * Example #4: When I press the keys "Alt+ArrowLeft"
59
+ * Example #5: When I press the keys "Control+Shift+P"
60
+ *
61
+ */
62
+ When(/^(I |we )*press the keys "([^"]*)"$/, async function (pronoun, keys) {
63
+ await this.page.keyboard.press(keys);
64
+ });
65
+
66
+ /**
67
+ * Press a key combination while a specific element is focused.
68
+ *
69
+ * Example #1: When I press the keys "Control+a" on the element "#editor"
70
+ * Example #2: When I press the keys "Meta+s" on the element "form"
71
+ * Example #3: And I press the keys "Shift+Tab" on the element "#email"
72
+ * Example #4: When I press the keys "Control+Enter" on the element "#message"
73
+ * Example #5: When I press the keys "Alt+Down" on the element ".combobox"
74
+ *
75
+ */
76
+ When(/^(I |we )*press the keys "([^"]*)" on the element "([^"]*)"$/, async function (pronoun, keys, sel) {
77
+ await this.page.locator(sel).first().press(keys);
78
+ });
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ // Link existence + href + title assertions.
4
+
5
+ const { When, Then } = require('@cucumber/cucumber');
6
+ const assert = require('assert');
7
+
8
+ function linkSelector(text) {
9
+ return `a:has-text("${text}")`;
10
+ }
11
+
12
+ /**
13
+ * Assert a link with the given visible text and an href containing a fragment exists.
14
+ *
15
+ * Example #1: Then the link "About" with the href "/about" should exist
16
+ * Example #2: Then the link "Sign in" with the href "/login" should exist
17
+ * Example #3: And the link "Pricing" with the href "/pricing" should exist
18
+ * Example #4: Then the link "Docs" with the href "docs.example.com" should exist
19
+ * Example #5: Then the link "Contact" with the href "/contact-us" should exist
20
+ *
21
+ */
22
+ Then('the link {string} with the href {string} should exist', async function (text, href) {
23
+ const loc = this.page.locator(`${linkSelector(text)}[href*="${href}"]`);
24
+ assert.ok(await loc.count() > 0, `Link "${text}" with href containing "${href}" not found.`);
25
+ });
26
+
27
+ /**
28
+ * Assert a link exists inside a specific parent element.
29
+ *
30
+ * Example #1: Then the link "Home" with the href "/" within the element "#main-nav" should exist
31
+ * Example #2: Then the link "Privacy" with the href "/privacy" within the element "footer" should exist
32
+ * Example #3: And the link "Sign in" with the href "/login" within the element ".header" should exist
33
+ * Example #4: Then the link "Docs" with the href "/docs" within the element "nav" should exist
34
+ * Example #5: Then the link "Pricing" with the href "/pricing" within the element ".cta-block" should exist
35
+ *
36
+ */
37
+ Then('the link {string} with the href {string} within the element {string} should exist', async function (text, href, parent) {
38
+ const loc = this.page.locator(`${parent} ${linkSelector(text)}[href*="${href}"]`);
39
+ assert.ok(await loc.count() > 0, `Link "${text}" with href containing "${href}" not found within "${parent}".`);
40
+ });
41
+
42
+ /**
43
+ * Assert NO link with the given visible text and href fragment exists.
44
+ *
45
+ * Example #1: Then the link "Sign in" with the href "/login" should not exist
46
+ * Example #2: Then the link "Admin" with the href "/admin" should not exist
47
+ * Example #3: And the link "Old docs" with the href "/v1/docs" should not exist
48
+ * Example #4: Then the link "Logout" with the href "/logout" should not exist
49
+ * Example #5: Then the link "Beta" with the href "/beta" should not exist
50
+ *
51
+ */
52
+ Then('the link {string} with the href {string} should not exist', async function (text, href) {
53
+ const loc = this.page.locator(`${linkSelector(text)}[href*="${href}"]`);
54
+ assert.strictEqual(await loc.count(), 0, `Link "${text}" with href containing "${href}" should not exist.`);
55
+ });
56
+
57
+ /**
58
+ * Assert NO link with text+href exists inside a specific parent element.
59
+ *
60
+ * Example #1: Then the link "Logout" with the href "/logout" within the element ".guest-nav" should not exist
61
+ * Example #2: Then the link "Admin" with the href "/admin" within the element "footer" should not exist
62
+ * Example #3: And the link "Beta" with the href "/beta" within the element "#main-nav" should not exist
63
+ * Example #4: Then the link "Old" with the href "/v1" within the element ".breadcrumb" should not exist
64
+ * Example #5: Then the link "Internal" with the href "/internal" within the element ".public-nav" should not exist
65
+ *
66
+ */
67
+ Then('the link {string} with the href {string} within the element {string} should not exist', async function (text, href, parent) {
68
+ const loc = this.page.locator(`${parent} ${linkSelector(text)}[href*="${href}"]`);
69
+ assert.strictEqual(await loc.count(), 0, `Link "${text}" with href containing "${href}" should not exist within "${parent}".`);
70
+ });
71
+
72
+ /**
73
+ * Assert at least one link has the exact `title` attribute.
74
+ *
75
+ * Example #1: Then the link with the title "Open menu" should exist
76
+ * Example #2: Then the link with the title "Edit profile" should exist
77
+ * Example #3: And the link with the title "Download PDF" should exist
78
+ * Example #4: Then the link with the title "Print page" should exist
79
+ * Example #5: Then the link with the title "Sign in" should exist
80
+ *
81
+ */
82
+ Then('the link with the title {string} should exist', async function (title) {
83
+ assert.ok(await this.page.locator(`a[title="${title}"]`).count() > 0, `Link with title "${title}" not found.`);
84
+ });
85
+
86
+ /**
87
+ * Assert NO link has the given exact `title` attribute.
88
+ *
89
+ * Example #1: Then the link with the title "Delete user" should not exist
90
+ * Example #2: Then the link with the title "Open admin" should not exist
91
+ * Example #3: And the link with the title "Edit billing" should not exist
92
+ * Example #4: Then the link with the title "Sign out" should not exist
93
+ * Example #5: Then the link with the title "Reveal secret" should not exist
94
+ *
95
+ */
96
+ Then('the link with the title {string} should not exist', async function (title) {
97
+ assert.strictEqual(await this.page.locator(`a[title="${title}"]`).count(), 0, `Link with title "${title}" should not exist.`);
98
+ });
99
+
100
+ /**
101
+ * Assert a link's href is absolute (starts with `http://` or `https://`).
102
+ *
103
+ * Example #1: Then the link "Twitter" should be an absolute link
104
+ * Example #2: Then the link "GitHub" should be an absolute link
105
+ * Example #3: And the link "Documentation" should be an absolute link
106
+ * Example #4: Then the link "Status page" should be an absolute link
107
+ * Example #5: Then the link "External docs" should be an absolute link
108
+ *
109
+ */
110
+ Then('the link {string} should be an absolute link', async function (text) {
111
+ const href = await this.page.locator(linkSelector(text)).first().getAttribute('href');
112
+ assert.ok(href && /^https?:\/\//.test(href), `Link "${text}" href "${href}" is not absolute.`);
113
+ });
114
+
115
+ /**
116
+ * Assert a link's href is relative (no `http://` / `https://` scheme).
117
+ *
118
+ * Example #1: Then the link "Home" should not be an absolute link
119
+ * Example #2: Then the link "About" should not be an absolute link
120
+ * Example #3: And the link "Privacy" should not be an absolute link
121
+ * Example #4: Then the link "Pricing" should not be an absolute link
122
+ * Example #5: Then the link "Docs" should not be an absolute link
123
+ *
124
+ */
125
+ Then('the link {string} should not be an absolute link', async function (text) {
126
+ const href = await this.page.locator(linkSelector(text)).first().getAttribute('href');
127
+ assert.ok(href && !/^https?:\/\//.test(href), `Link "${text}" href "${href}" should not be absolute.`);
128
+ });
129
+
130
+ /**
131
+ * Click a link addressed by its `title` attribute.
132
+ *
133
+ * Example #1: When I click on the link with the title "Open menu"
134
+ * Example #2: When I click on the link with the title "Edit profile"
135
+ * Example #3: And we click on the link with the title "Download PDF"
136
+ * Example #4: When I click on the link with the title "Print page"
137
+ * Example #5: When I click on the link with the title "Sign in"
138
+ *
139
+ */
140
+ When(/^(I |we )*click on the link with the title "([^"]*)"$/, async function (pronoun, title) {
141
+ await this.page.locator(`a[title="${title}"]`).first().click();
142
+ });