webship-js 2.0.2 → 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 (162) hide show
  1. package/AGENTS.md +109 -0
  2. package/CLAUDE.md +317 -0
  3. package/bin/generate-reports.js +181 -9
  4. package/cucumber.js +10 -4
  5. package/docs/00-quick-start.md +102 -0
  6. package/docs/01-getting-started.md +102 -0
  7. package/docs/02-bbr-smart-waits.md +77 -0
  8. package/docs/03-selector-registry.md +95 -0
  9. package/docs/04-step-reference.md +728 -0
  10. package/docs/05-web-first-assertions.md +91 -0
  11. package/docs/06-network-and-dialogs.md +83 -0
  12. package/docs/07-auth-state.md +75 -0
  13. package/docs/08-clock-mocking.md +59 -0
  14. package/docs/09-api-testing.md +114 -0
  15. package/docs/10-accessibility.md +167 -0
  16. package/docs/11-debugging.md +129 -0
  17. package/docs/12-ai-agent-guide.md +338 -0
  18. package/docs/13-faq.md +236 -0
  19. package/docs/14-recipes-cookbook.md +255 -0
  20. package/docs/15-tag-conventions.md +76 -0
  21. package/docs/advanced-screenshots/then-i-save-fullscreen-screenshot.md +36 -0
  22. package/docs/advanced-screenshots/then-i-save-width-x-height-screenshot.md +34 -0
  23. package/docs/advanced-screenshots/when-i-save-screenshot-name-filename.md +45 -0
  24. package/docs/advanced-screenshots.md +52 -0
  25. package/docs/advanced-selectors.md +18 -0
  26. package/docs/api-step-definitions.md +45 -0
  27. package/docs/diffy-step-definitions/then-compare-diffy-env1-env2.md +30 -0
  28. package/docs/diffy-step-definitions/then-create-diffy-comparison-name-value.md +21 -0
  29. package/docs/diffy-step-definitions/then-create-diffy-comparison.md +25 -0
  30. package/docs/diffy-step-definitions/then-create-diffy-screenshot-environment-name.md +35 -0
  31. package/docs/diffy-step-definitions/then-i-take-screenshot.md +21 -0
  32. package/docs/diffy-step-definitions/then-i-take-screenshots-all-breakpoints.md +27 -0
  33. package/docs/diffy-step-definitions/then-send-screenshots-diffy-name-value.md +27 -0
  34. package/docs/diffy-step-definitions/then-upload-folder-url-diffy-snapshotname.md +28 -0
  35. package/docs/diffy-step-definitions/then-wait-diffy-comparison-complete.md +21 -0
  36. package/docs/diffy-step-definitions/when-i-resize-window-number.md +29 -0
  37. package/docs/diffy-step-definitions.md +21 -0
  38. package/docs/global-settings.md +244 -0
  39. package/docs/index.md +104 -0
  40. package/docs/install-webship-js/ddev-webship-js.md +52 -0
  41. package/docs/install-webship-js.md +35 -0
  42. package/docs/overview.md +41 -0
  43. package/docs/step-definitions/given-i-am-anonymous-user.md +67 -0
  44. package/docs/step-definitions/given-i-am-homepage.md +68 -0
  45. package/docs/step-definitions/given-i-am-specific-page.md +72 -0
  46. package/docs/step-definitions/then-i-should-be.md +56 -0
  47. package/docs/step-definitions/then-i-should-see.md +62 -0
  48. package/docs/step-definitions/then-item-checkbox.md +54 -0
  49. package/docs/step-definitions/then-item-link-should-contain-url.md +84 -0
  50. package/docs/step-definitions/then-item-should-contain.md +67 -0
  51. package/docs/step-definitions/then-radio-button-value-should-be-selected.md +68 -0
  52. package/docs/step-definitions/then-response-status-code-should-be-number.md +69 -0
  53. package/docs/step-definitions/then-value-radio-button-selected.md +62 -0
  54. package/docs/step-definitions/when-i-attach-file-file-name-element.md +71 -0
  55. package/docs/step-definitions/when-i-check-checkbox.md +60 -0
  56. package/docs/step-definitions/when-i-click-link.md +51 -0
  57. package/docs/step-definitions/when-i-click-operation-text-row.md +71 -0
  58. package/docs/step-definitions/when-i-fill.md +59 -0
  59. package/docs/step-definitions/when-i-go-homepage.md +60 -0
  60. package/docs/step-definitions/when-i-go-specific-page.md +67 -0
  61. package/docs/step-definitions/when-i-move-backward-one-page.md +49 -0
  62. package/docs/step-definitions/when-i-move-forward-one-page.md +58 -0
  63. package/docs/step-definitions/when-i-press-button.md +58 -0
  64. package/docs/step-definitions/when-i-reload-page.md +51 -0
  65. package/docs/step-definitions/when-i-scroll.md +73 -0
  66. package/docs/step-definitions/when-i-select-option-select-list.md +53 -0
  67. package/docs/step-definitions/when-i-select-radio-button-value.md +62 -0
  68. package/docs/step-definitions/when-i-uncheck-checkbox.md +57 -0
  69. package/docs/step-definitions/when-i-wait-ajax-finish.md +64 -0
  70. package/docs/step-definitions/when-i-wait.md +62 -0
  71. package/docs/step-definitions.md +50 -0
  72. package/examples/a11y.html +31 -0
  73. package/examples/cookies.html +10 -0
  74. package/examples/date.html +12 -0
  75. package/examples/element.html +11 -0
  76. package/examples/field.html +24 -0
  77. package/examples/keyboard.html +11 -0
  78. package/examples/links.html +9 -0
  79. package/examples/modal.html +14 -0
  80. package/examples/path.html +3 -0
  81. package/examples/table.html +13 -0
  82. package/package.json +10 -3
  83. package/playwright.config.ts +3 -2
  84. package/tests/features/a11y.feature +39 -0
  85. package/tests/features/cookie.feature +13 -0
  86. package/tests/features/date.feature +11 -0
  87. package/tests/features/element.feature +16 -0
  88. package/tests/features/field.feature +25 -0
  89. package/tests/features/keyboard.feature +10 -0
  90. package/tests/features/link.feature +11 -0
  91. package/tests/features/modal-advanced-example.feature +1 -1
  92. package/tests/features/modal.feature +11 -0
  93. package/tests/features/path.feature +16 -0
  94. package/tests/features/response.feature +8 -0
  95. package/tests/features/responsive.feature +10 -0
  96. package/tests/features/table.feature +18 -0
  97. package/tests/features/wait.feature +7 -0
  98. package/tests/features/yaml.feature +102 -0
  99. package/tests/reports/README.md +55 -0
  100. package/tests/selectors/_canonical-keys.json +113 -0
  101. package/tests/selectors/back-end-selectors.json +7 -1
  102. package/tests/selectors/cms-contentful-admin.json +35 -0
  103. package/tests/selectors/cms-craft-admin.json +39 -0
  104. package/tests/selectors/cms-drupal-cms-gin.json +56 -0
  105. package/tests/selectors/cms-drupal-core-claro.json +50 -0
  106. package/tests/selectors/cms-generic-admin.json +34 -0
  107. package/tests/selectors/cms-ghost-admin.json +34 -0
  108. package/tests/selectors/cms-joomla-admin.json +41 -0
  109. package/tests/selectors/cms-magento2-admin.json +32 -0
  110. package/tests/selectors/cms-prestashop-admin.json +38 -0
  111. package/tests/selectors/cms-shopify-admin.json +25 -0
  112. package/tests/selectors/cms-strapi-admin.json +42 -0
  113. package/tests/selectors/cms-typo3-admin.json +41 -0
  114. package/tests/selectors/cms-woocommerce-front.json +50 -0
  115. package/tests/selectors/cms-wordpress-admin.json +31 -0
  116. package/tests/selectors/framework-ant-design.json +80 -0
  117. package/tests/selectors/framework-bootstrap.json +86 -0
  118. package/tests/selectors/framework-bulma.json +74 -0
  119. package/tests/selectors/framework-chakra.json +58 -0
  120. package/tests/selectors/framework-foundation.json +51 -0
  121. package/tests/selectors/framework-material-ui.json +72 -0
  122. package/tests/selectors/framework-shadcn.json +51 -0
  123. package/tests/selectors/framework-tailwind.json +40 -0
  124. package/tests/selectors/framework-vuetify.json +61 -0
  125. package/tests/step-definitions/a11y.steps.js +798 -0
  126. package/tests/step-definitions/action.steps.js +167 -0
  127. package/tests/step-definitions/{webship-api.js → api.steps.js} +24 -7
  128. package/tests/step-definitions/assertion.steps.js +352 -0
  129. package/tests/step-definitions/auth.steps.js +124 -0
  130. package/tests/step-definitions/clock.steps.js +128 -0
  131. package/tests/step-definitions/cookie.steps.js +216 -0
  132. package/tests/step-definitions/debug.steps.js +31 -0
  133. package/tests/step-definitions/dialog.steps.js +193 -0
  134. package/tests/step-definitions/element.steps.js +314 -0
  135. package/tests/step-definitions/field.steps.js +653 -0
  136. package/tests/step-definitions/file-download.steps.js +193 -0
  137. package/tests/step-definitions/form.steps.js +333 -0
  138. package/tests/step-definitions/iframe.steps.js +178 -0
  139. package/tests/step-definitions/input.steps.js +163 -0
  140. package/tests/step-definitions/javascript.steps.js +71 -0
  141. package/tests/step-definitions/keyboard.steps.js +78 -0
  142. package/tests/step-definitions/link.steps.js +142 -0
  143. package/tests/step-definitions/metatag.steps.js +91 -0
  144. package/tests/step-definitions/modal.steps.js +219 -0
  145. package/tests/step-definitions/navigation.steps.js +218 -0
  146. package/tests/step-definitions/network.steps.js +238 -0
  147. package/tests/step-definitions/path.steps.js +141 -0
  148. package/tests/step-definitions/response.steps.js +98 -0
  149. package/tests/step-definitions/responsive.steps.js +123 -0
  150. package/tests/step-definitions/rest.steps.js +111 -0
  151. package/tests/step-definitions/{webship-screenshot.js → screenshot.steps.js} +1 -5
  152. package/tests/step-definitions/scroll.steps.js +189 -0
  153. package/tests/step-definitions/{webship-selectors.js → selectors.steps.js} +46 -11
  154. package/tests/step-definitions/storage.steps.js +194 -0
  155. package/tests/step-definitions/table.steps.js +181 -0
  156. package/tests/step-definitions/wait.steps.js +400 -0
  157. package/tests/step-definitions/web-first.steps.js +296 -0
  158. package/tests/step-definitions/webship.js +552 -1507
  159. package/tests/step-definitions/xml.steps.js +409 -0
  160. package/tests/step-definitions/yaml.steps.js +911 -0
  161. package/tests/step-definitions-diffy/webship-diffy.js +0 -13
  162. package/tsconfig.json +19 -3
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ // Authentication-state helpers built on Playwright's `storageState` API.
4
+ //
5
+ // Save the cookies + localStorage of an authenticated context to a JSON file
6
+ // once, then restore that snapshot in later scenarios so each test does not
7
+ // have to walk through the login UI. This is the single biggest speedup
8
+ // available for suites that touch authenticated pages — typical savings of
9
+ // 1-3 seconds per scenario.
10
+ //
11
+ // Recommended layout:
12
+ //
13
+ // tests/auth/admin.json
14
+ // tests/auth/editor.json
15
+ // tests/auth/customer.json
16
+ //
17
+ // Recommended setup feature: tag a one-shot scenario `@auth-setup`, run it
18
+ // once via `npx cucumber-js --tags @auth-setup` after every credential
19
+ // rotation, and let everyday scenarios restore the snapshot.
20
+
21
+ const { Given, When } = require('@cucumber/cucumber');
22
+ const path = require('path');
23
+ const fs = require('fs');
24
+
25
+ function resolveStoragePath(p) {
26
+ return path.isAbsolute(p) ? p : path.join(process.cwd(), p);
27
+ }
28
+
29
+ /**
30
+ * Save the current browser context's cookies + localStorage to a JSON file.
31
+ *
32
+ * Run this AFTER a successful interactive login. The destination file is
33
+ * created (with parent directories) if it does not exist; existing files are
34
+ * overwritten.
35
+ *
36
+ * Example #1: When I save the auth state to "tests/auth/admin.json"
37
+ * Example #2: Given I am on "/login"
38
+ * When I fill in "admin@example.com" for "Email"
39
+ * And I fill in "secret" for "Password"
40
+ * And I press "Sign in"
41
+ * And I wait until the URL contains "/dashboard"
42
+ * Then I save the auth state to "tests/auth/admin.json"
43
+ * Example #3: When I save the auth state to "tests/auth/editor.json"
44
+ * Example #4: When we save the auth state to "tests/auth/customer.json"
45
+ * Example #5: When I save the auth state to "/tmp/admin-state.json"
46
+ *
47
+ */
48
+ When(/^(I |we )*save the auth state to "([^"]*)"$/, async function (pronoun, target) {
49
+ const file = resolveStoragePath(target);
50
+ fs.mkdirSync(path.dirname(file), { recursive: true });
51
+ await this.context.storageState({ path: file });
52
+ });
53
+
54
+ /**
55
+ * Restore cookies + localStorage from a previously saved JSON file.
56
+ *
57
+ * The current browser context is closed and a fresh one is opened with the
58
+ * saved state. The webship-js init script (AJAX/timer/mutation tracker) is
59
+ * re-installed automatically so smart waits keep working. Subsequent steps
60
+ * proceed against the restored, authenticated session.
61
+ *
62
+ * Example #1: Given I restore the auth state from "tests/auth/admin.json"
63
+ * Example #2: Given I restore the auth state from "tests/auth/editor.json"
64
+ * And I am on "/admin/products"
65
+ * Example #3: Given I restore the auth state from "tests/auth/customer.json"
66
+ * And I am on "/account/orders"
67
+ * Example #4: Given we restore the auth state from "tests/auth/admin.json"
68
+ * Example #5: Given I restore the auth state from "tests/auth/admin.json"
69
+ * And I am on "/dashboard"
70
+ * Then "<#user-list>" should have a count of 5 within 5 seconds
71
+ *
72
+ */
73
+ Given(/^(I |we )*restore the auth state from "([^"]*)"$/, async function (pronoun, source) {
74
+ const file = resolveStoragePath(source);
75
+ if (!fs.existsSync(file)) {
76
+ throw new Error(`Auth state file not found: ${file}`);
77
+ }
78
+ const playwrightConfig = require(path.join(process.cwd(), 'playwright.config'));
79
+ const newContext = await this.playwrightBrowser.newContext({
80
+ ...playwrightConfig.contextOptions,
81
+ storageState: file,
82
+ });
83
+ await newContext.addInitScript(() => {
84
+ if (window.__webshipAjaxInstalled) return;
85
+ window.__webshipAjaxInstalled = true;
86
+ window.__webshipAjaxCount = 0;
87
+ window.__webshipPendingTimers = 0;
88
+ window.__webshipLastMutation = Date.now();
89
+ });
90
+ if (this.context) await this.context.close();
91
+ this.context = newContext;
92
+ this.page = await this.context.newPage();
93
+ });
94
+
95
+ /**
96
+ * Clear cookies and localStorage / sessionStorage for the current context.
97
+ *
98
+ * Use to anonymize a session mid-scenario, e.g. after asserting a logged-in
99
+ * action you may want to verify the same path returns 302 / login form for
100
+ * an anonymous visitor.
101
+ *
102
+ * Example #1: Given I clear the auth state
103
+ * Example #2: Given I restore the auth state from "tests/auth/admin.json"
104
+ * And I am on "/dashboard"
105
+ * Given I clear the auth state
106
+ * When I am on "/dashboard"
107
+ * Then I should see "Sign in"
108
+ * Example #3: Given we clear the auth state
109
+ * Example #4: When I press "Logout"
110
+ * And I clear the auth state
111
+ * Example #5: Given I clear the auth state
112
+ * When I am on the homepage
113
+ * Then I should see "Login"
114
+ *
115
+ */
116
+ Given(/^(I |we )*clear the auth state$/, async function () {
117
+ await this.context.clearCookies();
118
+ try {
119
+ await this.page.evaluate(() => {
120
+ try { localStorage.clear(); } catch { /* no-op */ }
121
+ try { sessionStorage.clear(); } catch { /* no-op */ }
122
+ });
123
+ } catch { /* page may not be on a real URL yet */ }
124
+ });
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ // Clock / time-mocking steps backed by Playwright's `page.clock` API.
4
+ //
5
+ // Useful for testing relative-time UIs ("5 minutes ago"), debounced inputs,
6
+ // throttled re-renders, scheduled UI changes (toast auto-dismiss, session
7
+ // timeout), and any flow gated on `Date.now()` or `setTimeout`.
8
+ //
9
+ // Once the fake clock is installed, page-level `Date.now()` and `new Date()`
10
+ // return the fake time, and pending timers stay paused until explicitly
11
+ // advanced.
12
+
13
+ const { Given, When } = require('@cucumber/cucumber');
14
+
15
+ /**
16
+ * Install a fake clock anchored at an ISO 8601 instant.
17
+ *
18
+ * After this step, `Date.now()` inside the page returns the fake time and
19
+ * `setTimeout` / `setInterval` callbacks queue but do not fire until you
20
+ * advance the clock.
21
+ *
22
+ * Example #1: Given the system time is "2026-05-08T10:00:00Z"
23
+ * Example #2: Given the system time is "2026-01-01T00:00:00Z"
24
+ * And I am on "/feed"
25
+ * Example #3: Given the system time is "2026-12-31T23:59:55Z"
26
+ * And I am on "/countdown"
27
+ * Example #4: Given the system time is "2026-05-08T10:00:00Z"
28
+ * And I am on "/feed"
29
+ * And "<.timestamp>" should have text "just now"
30
+ * Example #5: Given the system time is "2026-07-04T12:00:00-04:00"
31
+ * And I am on "/holiday-banner"
32
+ *
33
+ */
34
+ Given(/^the system time is "([^"]*)"$/, async function (iso) {
35
+ await this.page.clock.install({ time: new Date(iso) });
36
+ });
37
+
38
+ /**
39
+ * Advance the fake clock forward by N milliseconds, firing every queued
40
+ * `setTimeout` / `setInterval` callback scheduled within that interval.
41
+ *
42
+ * Example #1: When I advance the clock by 500 ms
43
+ * Example #2: When I advance the clock by 1500 ms
44
+ * Example #3: When we advance the clock by 250 ms
45
+ * Example #4: And I advance the clock by 100 ms
46
+ * Example #5: When I advance the clock by 60000 ms
47
+ *
48
+ */
49
+ When(/^(I |we )*advance the clock by (\d+) ?ms$/, async function (pronoun, ms) {
50
+ await this.page.clock.runFor(parseInt(ms, 10));
51
+ });
52
+
53
+ /**
54
+ * Advance the fake clock forward by N seconds.
55
+ *
56
+ * Example #1: When I advance the clock by 30 seconds
57
+ * Example #2: When I advance the clock by 5 seconds
58
+ * Example #3: When we advance the clock by 1 second
59
+ * Example #4: And I advance the clock by 10 seconds
60
+ * Example #5: When I advance the clock by 90 seconds
61
+ *
62
+ */
63
+ When(/^(I |we )*advance the clock by (\d+) seconds?$/, async function (pronoun, seconds) {
64
+ await this.page.clock.runFor(parseInt(seconds, 10) * 1000);
65
+ });
66
+
67
+ /**
68
+ * Advance the fake clock forward by N minutes.
69
+ *
70
+ * Example #1: When I advance the clock by 5 minutes
71
+ * Example #2: When I advance the clock by 1 minute
72
+ * Example #3: When we advance the clock by 14 minutes
73
+ * Example #4: And I advance the clock by 30 minutes
74
+ * Example #5: When I advance the clock by 60 minutes
75
+ *
76
+ */
77
+ When(/^(I |we )*advance the clock by (\d+) minutes?$/, async function (pronoun, minutes) {
78
+ await this.page.clock.runFor(parseInt(minutes, 10) * 60 * 1000);
79
+ });
80
+
81
+ /**
82
+ * Pause the fake clock — no further timer callbacks fire until resumed or
83
+ * explicitly advanced. Useful between actions when you do not want a long
84
+ * tick to fire mid-step.
85
+ *
86
+ * Example #1: When I pause the clock
87
+ * Example #2: Given the system time is "2026-05-08T10:00:00Z"
88
+ * When I pause the clock
89
+ * Example #3: When we pause the clock
90
+ * Example #4: And I pause the clock
91
+ * Example #5: When I pause the clock
92
+ * Then "<.timer>" should have text "00:00"
93
+ *
94
+ */
95
+ When(/^(I |we )*pause the clock$/, async function () {
96
+ await this.page.clock.pauseAt(await this.page.evaluate(() => Date.now()));
97
+ });
98
+
99
+ /**
100
+ * Resume the fake clock from the current paused time.
101
+ *
102
+ * Example #1: When I resume the clock
103
+ * Example #2: When I pause the clock
104
+ * And I resume the clock
105
+ * Example #3: When we resume the clock
106
+ * Example #4: And I resume the clock
107
+ * Example #5: When I resume the clock
108
+ * And I advance the clock by 5 seconds
109
+ *
110
+ */
111
+ When(/^(I |we )*resume the clock$/, async function () {
112
+ await this.page.clock.resume();
113
+ });
114
+
115
+ /**
116
+ * Set the fake clock to a specific time WITHOUT advancing through it. Use
117
+ * `advance` if you want pending timers in the gap to fire.
118
+ *
119
+ * Example #1: When I set the system time to "2026-05-08T12:30:00Z"
120
+ * Example #2: When I set the system time to "2026-12-31T23:59:55Z"
121
+ * Example #3: When we set the system time to "2026-01-01T00:00:00Z"
122
+ * Example #4: And I set the system time to "2026-07-04T08:00:00-04:00"
123
+ * Example #5: When I set the system time to "2027-01-01T00:00:00Z"
124
+ *
125
+ */
126
+ When(/^(I |we )*set the system time to "([^"]*)"$/, async function (pronoun, iso) {
127
+ await this.page.clock.setSystemTime(new Date(iso));
128
+ });
@@ -0,0 +1,216 @@
1
+ 'use strict';
2
+
3
+ // Cookie existence and value assertions (exact and partial matching) using
4
+ // Playwright's `BrowserContext.cookies()` API.
5
+
6
+ const { Then } = require('@cucumber/cucumber');
7
+ const assert = require('assert');
8
+
9
+ async function getCookies(world) {
10
+ return world.context ? await world.context.cookies() : [];
11
+ }
12
+
13
+ function findByName(cookies, name) {
14
+ return cookies.find((c) => c.name === name);
15
+ }
16
+
17
+ function findByPartialName(cookies, partial) {
18
+ return cookies.find((c) => c.name.indexOf(partial) !== -1);
19
+ }
20
+
21
+ /**
22
+ * Assert that a cookie with the exact name exists in the browser context.
23
+ *
24
+ * Example #1: Then a cookie with the name "session_id" should exist
25
+ * Example #2: Then a cookie with the name "auth_token" should exist
26
+ * Example #3: And a cookie with the name "lang" should exist
27
+ * Example #4: Then a cookie with the name "consent" should exist
28
+ * Example #5: When I press "Sign in"
29
+ * Then a cookie with the name "session" should exist
30
+ *
31
+ */
32
+ Then('a cookie with the name {string} should exist', async function (name) {
33
+ const cookies = await getCookies(this);
34
+ assert.ok(findByName(cookies, name), `Cookie "${name}" was not found.`);
35
+ });
36
+
37
+ /**
38
+ * Assert that a cookie with the exact name AND exact value exists.
39
+ *
40
+ * Example #1: Then a cookie with the name "lang" and the value "en" should exist
41
+ * Example #2: Then a cookie with the name "consent" and the value "accepted" should exist
42
+ * Example #3: And a cookie with the name "ab_bucket" and the value "variant-b" should exist
43
+ * Example #4: Then a cookie with the name "theme" and the value "dark" should exist
44
+ * Example #5: When I check "Remember me"
45
+ * And I press "Sign in"
46
+ * Then a cookie with the name "remember" and the value "1" should exist
47
+ *
48
+ */
49
+ Then('a cookie with the name {string} and the value {string} should exist', async function (name, value) {
50
+ const cookies = await getCookies(this);
51
+ const c = findByName(cookies, name);
52
+ assert.ok(c, `Cookie "${name}" was not found.`);
53
+ assert.strictEqual(c.value, value, `Cookie "${name}" has value "${c.value}", expected "${value}".`);
54
+ });
55
+
56
+ /**
57
+ * Assert a cookie with the exact name has a value containing a substring.
58
+ *
59
+ * Example #1: Then a cookie with the name "session_id" and a value containing "abc" should exist
60
+ * Example #2: Then a cookie with the name "auth" and a value containing "Bearer" should exist
61
+ * Example #3: And a cookie with the name "preferences" and a value containing "darkmode" should exist
62
+ * Example #4: Then a cookie with the name "tracking" and a value containing "v2-" should exist
63
+ * Example #5: Then a cookie with the name "csrf" and a value containing "token=" should exist
64
+ *
65
+ */
66
+ Then('a cookie with the name {string} and a value containing {string} should exist', async function (name, partial) {
67
+ const cookies = await getCookies(this);
68
+ const c = findByName(cookies, name);
69
+ assert.ok(c, `Cookie "${name}" was not found.`);
70
+ assert.ok(c.value.indexOf(partial) !== -1, `Cookie "${name}" value "${c.value}" does not contain "${partial}".`);
71
+ });
72
+
73
+ /**
74
+ * Assert a cookie whose name contains a substring exists.
75
+ *
76
+ * Example #1: Then a cookie with a name containing "session" should exist
77
+ * Example #2: Then a cookie with a name containing "_csrf" should exist
78
+ * Example #3: And a cookie with a name containing "tracking" should exist
79
+ * Example #4: Then a cookie with a name containing "auth" should exist
80
+ * Example #5: Then a cookie with a name containing "lang_" should exist
81
+ *
82
+ */
83
+ Then('a cookie with a name containing {string} should exist', async function (partial) {
84
+ const cookies = await getCookies(this);
85
+ assert.ok(findByPartialName(cookies, partial), `No cookie with name containing "${partial}" was found.`);
86
+ });
87
+
88
+ /**
89
+ * Assert a cookie whose name contains a substring has the exact value.
90
+ *
91
+ * Example #1: Then a cookie with a name containing "session" and the value "active" should exist
92
+ * Example #2: Then a cookie with a name containing "auth" and the value "1" should exist
93
+ * Example #3: And a cookie with a name containing "lang_" and the value "en" should exist
94
+ * Example #4: Then a cookie with a name containing "feature_" and the value "on" should exist
95
+ * Example #5: Then a cookie with a name containing "_pref" and the value "dark" should exist
96
+ *
97
+ */
98
+ Then('a cookie with a name containing {string} and the value {string} should exist', async function (partial, value) {
99
+ const cookies = await getCookies(this);
100
+ const found = cookies.find((c) => c.name.indexOf(partial) !== -1 && c.value === value);
101
+ assert.ok(found, `No cookie with name containing "${partial}" and value "${value}" was found.`);
102
+ });
103
+
104
+ /**
105
+ * Assert a cookie whose name contains substring A has a value containing substring B.
106
+ *
107
+ * Example #1: Then a cookie with a name containing "session" and a value containing "active" should exist
108
+ * Example #2: Then a cookie with a name containing "auth" and a value containing "Bearer" should exist
109
+ * Example #3: And a cookie with a name containing "tracking" and a value containing "v2-" should exist
110
+ * Example #4: Then a cookie with a name containing "csrf" and a value containing "token=" should exist
111
+ * Example #5: Then a cookie with a name containing "_pref" and a value containing "dark" should exist
112
+ *
113
+ */
114
+ Then('a cookie with a name containing {string} and a value containing {string} should exist', async function (partialName, partialValue) {
115
+ const cookies = await getCookies(this);
116
+ const found = cookies.find((c) => c.name.indexOf(partialName) !== -1 && c.value.indexOf(partialValue) !== -1);
117
+ assert.ok(found, `No cookie with name containing "${partialName}" and value containing "${partialValue}" was found.`);
118
+ });
119
+
120
+ /**
121
+ * Assert a cookie with the exact name does NOT exist.
122
+ *
123
+ * Example #1: Then a cookie with the name "session_id" should not exist
124
+ * Example #2: Then a cookie with the name "auth_token" should not exist
125
+ * Example #3: And a cookie with the name "tracking" should not exist
126
+ * Example #4: When I press "Logout"
127
+ * Then a cookie with the name "session" should not exist
128
+ * Example #5: Given all cookies are cleared
129
+ * Then a cookie with the name "lang" should not exist
130
+ *
131
+ */
132
+ Then('a cookie with the name {string} should not exist', async function (name) {
133
+ const cookies = await getCookies(this);
134
+ assert.ok(!findByName(cookies, name), `Cookie "${name}" should not exist but it does.`);
135
+ });
136
+
137
+ /**
138
+ * Assert a cookie with the exact name+value does NOT exist.
139
+ *
140
+ * Example #1: Then a cookie with the name "lang" and the value "fr" should not exist
141
+ * Example #2: Then a cookie with the name "consent" and the value "rejected" should not exist
142
+ * Example #3: And a cookie with the name "theme" and the value "dark" should not exist
143
+ * Example #4: Then a cookie with the name "ab_bucket" and the value "variant-c" should not exist
144
+ * Example #5: Then a cookie with the name "remember" and the value "0" should not exist
145
+ *
146
+ */
147
+ Then('a cookie with the name {string} and the value {string} should not exist', async function (name, value) {
148
+ const cookies = await getCookies(this);
149
+ const c = findByName(cookies, name);
150
+ assert.ok(!c || c.value !== value, `Cookie "${name}" with value "${value}" should not exist.`);
151
+ });
152
+
153
+ /**
154
+ * Assert a cookie with the exact name does not contain a substring in its value.
155
+ *
156
+ * Example #1: Then a cookie with the name "preferences" and a value containing "lightmode" should not exist
157
+ * Example #2: Then a cookie with the name "tracking" and a value containing "v1-" should not exist
158
+ * Example #3: And a cookie with the name "auth" and a value containing "Basic" should not exist
159
+ * Example #4: Then a cookie with the name "session" and a value containing "expired" should not exist
160
+ * Example #5: Then a cookie with the name "csrf" and a value containing "invalid" should not exist
161
+ *
162
+ */
163
+ Then('a cookie with the name {string} and a value containing {string} should not exist', async function (name, partial) {
164
+ const cookies = await getCookies(this);
165
+ const c = findByName(cookies, name);
166
+ assert.ok(!c || c.value.indexOf(partial) === -1, `Cookie "${name}" should not contain value "${partial}".`);
167
+ });
168
+
169
+ /**
170
+ * Assert no cookie name contains a substring.
171
+ *
172
+ * Example #1: Then a cookie with a name containing "old_" should not exist
173
+ * Example #2: Then a cookie with a name containing "_legacy" should not exist
174
+ * Example #3: And a cookie with a name containing "deprecated" should not exist
175
+ * Example #4: Given all cookies are cleared
176
+ * Then a cookie with a name containing "session" should not exist
177
+ * Example #5: When I press "Logout"
178
+ * Then a cookie with a name containing "auth" should not exist
179
+ *
180
+ */
181
+ Then('a cookie with a name containing {string} should not exist', async function (partial) {
182
+ const cookies = await getCookies(this);
183
+ assert.ok(!findByPartialName(cookies, partial), `Cookie with name containing "${partial}" should not exist.`);
184
+ });
185
+
186
+ /**
187
+ * Assert no cookie name+value pair (with partial name) matches.
188
+ *
189
+ * Example #1: Then a cookie with a name containing "session" and the value "expired" should not exist
190
+ * Example #2: Then a cookie with a name containing "auth" and the value "anonymous" should not exist
191
+ * Example #3: And a cookie with a name containing "feature_" and the value "off" should not exist
192
+ * Example #4: Then a cookie with a name containing "lang_" and the value "xx" should not exist
193
+ * Example #5: Then a cookie with a name containing "_pref" and the value "default" should not exist
194
+ *
195
+ */
196
+ Then('a cookie with a name containing {string} and the value {string} should not exist', async function (partial, value) {
197
+ const cookies = await getCookies(this);
198
+ const found = cookies.find((c) => c.name.indexOf(partial) !== -1 && c.value === value);
199
+ assert.ok(!found, `Cookie with name containing "${partial}" and value "${value}" should not exist.`);
200
+ });
201
+
202
+ /**
203
+ * Assert no cookie partial-name + partial-value pair matches.
204
+ *
205
+ * Example #1: Then a cookie with a name containing "session" and a value containing "old" should not exist
206
+ * Example #2: Then a cookie with a name containing "auth" and a value containing "Basic" should not exist
207
+ * Example #3: And a cookie with a name containing "tracking" and a value containing "v0-" should not exist
208
+ * Example #4: Then a cookie with a name containing "_pref" and a value containing "lightmode" should not exist
209
+ * Example #5: Then a cookie with a name containing "csrf" and a value containing "invalid" should not exist
210
+ *
211
+ */
212
+ Then('a cookie with a name containing {string} and a value containing {string} should not exist', async function (partialName, partialValue) {
213
+ const cookies = await getCookies(this);
214
+ const found = cookies.find((c) => c.name.indexOf(partialName) !== -1 && c.value.indexOf(partialValue) !== -1);
215
+ assert.ok(!found, `Cookie with name containing "${partialName}" and value containing "${partialValue}" should not exist.`);
216
+ });
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ // Debug helpers — print current URL, full HTML response, etc. Use sparingly
4
+ // and strip before merging.
5
+
6
+ const { Then } = require('@cucumber/cucumber');
7
+
8
+ /**
9
+ * Print the current page URL to console (debug).
10
+ *
11
+ * Example #1: Then print current URL
12
+ * Example #2: When print current URL
13
+ * Example #3: And print current URL
14
+ */
15
+ Then(/^print current URL$/, function () {
16
+ console.log('\n--- Current URL ---');
17
+ console.log(` ${this.page.url()}`);
18
+ });
19
+
20
+ /**
21
+ * Print the full page HTML (last response) to console (debug).
22
+ *
23
+ * Example #1: Then print last response
24
+ * Example #2: When print last response
25
+ * Example #3: And print last response
26
+ */
27
+ Then(/^print last response$/, async function () {
28
+ const html = await this.page.content();
29
+ console.log('\n--- Last Response (HTML) ---');
30
+ console.log(html);
31
+ });