webship-js 2.0.2 → 2.0.4

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 (181) hide show
  1. package/.circleci/config.yml +7 -31
  2. package/.drone.yml +68 -0
  3. package/.harness/webship-js-pipeline.yml +101 -0
  4. package/.semaphore/semaphore.yml +58 -0
  5. package/.teamcity/pom.xml +52 -0
  6. package/.teamcity/settings.kts +92 -0
  7. package/.travis.yml +24 -3
  8. package/AGENTS.md +109 -0
  9. package/CLAUDE.md +317 -0
  10. package/Jenkinsfile +54 -0
  11. package/azure-pipelines.yml +82 -0
  12. package/bamboo-specs/bamboo.yml +131 -0
  13. package/bin/generate-reports.js +181 -9
  14. package/buildspec.yml +56 -0
  15. package/cloudbuild.yaml +49 -0
  16. package/codefresh.yml +77 -0
  17. package/cucumber.js +48 -5
  18. package/docs/00-quick-start.md +102 -0
  19. package/docs/01-getting-started.md +102 -0
  20. package/docs/02-bbr-smart-waits.md +77 -0
  21. package/docs/03-selector-registry.md +95 -0
  22. package/docs/04-step-reference.md +799 -0
  23. package/docs/05-web-first-assertions.md +91 -0
  24. package/docs/06-network-and-dialogs.md +83 -0
  25. package/docs/07-auth-state.md +75 -0
  26. package/docs/08-clock-mocking.md +59 -0
  27. package/docs/09-api-testing.md +114 -0
  28. package/docs/10-accessibility.md +167 -0
  29. package/docs/11-debugging.md +129 -0
  30. package/docs/12-ai-agent-guide.md +338 -0
  31. package/docs/13-faq.md +236 -0
  32. package/docs/14-recipes-cookbook.md +255 -0
  33. package/docs/15-tag-conventions.md +76 -0
  34. package/docs/16-ci-cd.md +879 -0
  35. package/docs/README.md +113 -0
  36. package/docs/advanced-screenshots/then-i-save-fullscreen-screenshot.md +36 -0
  37. package/docs/advanced-screenshots/then-i-save-width-x-height-screenshot.md +34 -0
  38. package/docs/advanced-screenshots/when-i-save-screenshot-name-filename.md +45 -0
  39. package/docs/advanced-screenshots.md +52 -0
  40. package/docs/advanced-selectors.md +18 -0
  41. package/docs/api-step-definitions.md +45 -0
  42. package/docs/diffy-step-definitions/then-compare-diffy-env1-env2.md +30 -0
  43. package/docs/diffy-step-definitions/then-create-diffy-comparison-name-value.md +21 -0
  44. package/docs/diffy-step-definitions/then-create-diffy-comparison.md +25 -0
  45. package/docs/diffy-step-definitions/then-create-diffy-screenshot-environment-name.md +35 -0
  46. package/docs/diffy-step-definitions/then-i-take-screenshot.md +21 -0
  47. package/docs/diffy-step-definitions/then-i-take-screenshots-all-breakpoints.md +27 -0
  48. package/docs/diffy-step-definitions/then-send-screenshots-diffy-name-value.md +27 -0
  49. package/docs/diffy-step-definitions/then-upload-folder-url-diffy-snapshotname.md +28 -0
  50. package/docs/diffy-step-definitions/then-wait-diffy-comparison-complete.md +21 -0
  51. package/docs/diffy-step-definitions/when-i-resize-window-number.md +29 -0
  52. package/docs/diffy-step-definitions.md +21 -0
  53. package/docs/global-settings.md +295 -0
  54. package/docs/install-webship-js/ddev-webship-js.md +52 -0
  55. package/docs/install-webship-js.md +35 -0
  56. package/docs/overview.md +41 -0
  57. package/docs/step-definitions/given-i-am-anonymous-user.md +67 -0
  58. package/docs/step-definitions/given-i-am-homepage.md +68 -0
  59. package/docs/step-definitions/given-i-am-specific-page.md +72 -0
  60. package/docs/step-definitions/then-i-should-be.md +56 -0
  61. package/docs/step-definitions/then-i-should-see.md +62 -0
  62. package/docs/step-definitions/then-item-checkbox.md +54 -0
  63. package/docs/step-definitions/then-item-link-should-contain-url.md +84 -0
  64. package/docs/step-definitions/then-item-should-contain.md +67 -0
  65. package/docs/step-definitions/then-radio-button-value-should-be-selected.md +68 -0
  66. package/docs/step-definitions/then-response-status-code-should-be-number.md +69 -0
  67. package/docs/step-definitions/then-value-radio-button-selected.md +62 -0
  68. package/docs/step-definitions/when-i-attach-file-file-name-element.md +71 -0
  69. package/docs/step-definitions/when-i-check-checkbox.md +60 -0
  70. package/docs/step-definitions/when-i-click-link.md +51 -0
  71. package/docs/step-definitions/when-i-click-operation-text-row.md +71 -0
  72. package/docs/step-definitions/when-i-fill.md +59 -0
  73. package/docs/step-definitions/when-i-go-homepage.md +60 -0
  74. package/docs/step-definitions/when-i-go-specific-page.md +67 -0
  75. package/docs/step-definitions/when-i-move-backward-one-page.md +49 -0
  76. package/docs/step-definitions/when-i-move-forward-one-page.md +58 -0
  77. package/docs/step-definitions/when-i-press-button.md +58 -0
  78. package/docs/step-definitions/when-i-reload-page.md +51 -0
  79. package/docs/step-definitions/when-i-scroll.md +73 -0
  80. package/docs/step-definitions/when-i-select-option-select-list.md +53 -0
  81. package/docs/step-definitions/when-i-select-radio-button-value.md +62 -0
  82. package/docs/step-definitions/when-i-uncheck-checkbox.md +57 -0
  83. package/docs/step-definitions/when-i-wait-ajax-finish.md +64 -0
  84. package/docs/step-definitions/when-i-wait.md +62 -0
  85. package/docs/step-definitions.md +50 -0
  86. package/examples/a11y.html +31 -0
  87. package/examples/cookies.html +10 -0
  88. package/examples/date.html +12 -0
  89. package/examples/element.html +11 -0
  90. package/examples/field.html +24 -0
  91. package/examples/keyboard.html +11 -0
  92. package/examples/links.html +9 -0
  93. package/examples/modal.html +14 -0
  94. package/examples/path.html +3 -0
  95. package/examples/table.html +13 -0
  96. package/examples/video-demo.html +43 -0
  97. package/package.json +10 -3
  98. package/playwright.config.ts +3 -2
  99. package/tests/features/a11y.feature +39 -0
  100. package/tests/features/cookie.feature +13 -0
  101. package/tests/features/date.feature +11 -0
  102. package/tests/features/element.feature +16 -0
  103. package/tests/features/field.feature +25 -0
  104. package/tests/features/keyboard.feature +10 -0
  105. package/tests/features/link.feature +11 -0
  106. package/tests/features/modal-advanced-example.feature +1 -1
  107. package/tests/features/modal.feature +11 -0
  108. package/tests/features/path.feature +16 -0
  109. package/tests/features/response.feature +8 -0
  110. package/tests/features/responsive.feature +10 -0
  111. package/tests/features/table.feature +18 -0
  112. package/tests/features/video.feature +18 -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 +7 -1
  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/step-definitions/a11y.steps.js +800 -0
  142. package/tests/step-definitions/action.steps.js +167 -0
  143. package/tests/step-definitions/{webship-api.js → api.steps.js} +41 -23
  144. package/tests/step-definitions/assertion.steps.js +352 -0
  145. package/tests/step-definitions/auth.steps.js +126 -0
  146. package/tests/step-definitions/clock.steps.js +128 -0
  147. package/tests/step-definitions/cookie.steps.js +216 -0
  148. package/tests/step-definitions/debug.steps.js +39 -0
  149. package/tests/step-definitions/dialog.steps.js +193 -0
  150. package/tests/step-definitions/element.steps.js +356 -0
  151. package/tests/step-definitions/field.steps.js +653 -0
  152. package/tests/step-definitions/file-download.steps.js +211 -0
  153. package/tests/step-definitions/form.steps.js +333 -0
  154. package/tests/step-definitions/iframe.steps.js +228 -0
  155. package/tests/step-definitions/input.steps.js +202 -0
  156. package/tests/step-definitions/javascript.steps.js +232 -0
  157. package/tests/step-definitions/keyboard.steps.js +112 -0
  158. package/tests/step-definitions/link.steps.js +142 -0
  159. package/tests/step-definitions/metatag.steps.js +91 -0
  160. package/tests/step-definitions/modal.steps.js +244 -0
  161. package/tests/step-definitions/navigation.steps.js +218 -0
  162. package/tests/step-definitions/network.steps.js +280 -0
  163. package/tests/step-definitions/path.steps.js +141 -0
  164. package/tests/step-definitions/response.steps.js +98 -0
  165. package/tests/step-definitions/responsive.steps.js +125 -0
  166. package/tests/step-definitions/rest.steps.js +111 -0
  167. package/tests/step-definitions/{webship-screenshot.js → screenshot.steps.js} +1 -5
  168. package/tests/step-definitions/scroll.steps.js +189 -0
  169. package/tests/step-definitions/{webship-selectors.js → selectors.steps.js} +64 -27
  170. package/tests/step-definitions/storage.steps.js +194 -0
  171. package/tests/step-definitions/table.steps.js +181 -0
  172. package/tests/step-definitions/video.steps.js +178 -0
  173. package/tests/step-definitions/wait.steps.js +400 -0
  174. package/tests/step-definitions/web-first.steps.js +298 -0
  175. package/tests/step-definitions/webship.js +741 -1477
  176. package/tests/step-definitions/xml.steps.js +411 -0
  177. package/tests/step-definitions/yaml.steps.js +913 -0
  178. package/tests/step-definitions-diffy/webship-diffy.js +0 -13
  179. package/tsconfig.json +19 -3
  180. package/videos/README.md +32 -0
  181. package/.travis-ci.yml +0 -16
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ // Inspect HTTP response headers using Playwright's request API on the current page URL.
4
+
5
+ const { Then, Before } = require('@cucumber/cucumber');
6
+ const assert = require('assert');
7
+
8
+ // Capture response headers from navigation events, with page.request fallback.
9
+ Before({ order: 100 }, async function () {
10
+ if (!this.page) return;
11
+ this._lastResponseHeaders = null;
12
+ this._lastResponseStatus = null;
13
+ this.page.on('response', (resp) => {
14
+ try {
15
+ if (resp.request().isNavigationRequest() && resp.frame() === this.page.mainFrame()) {
16
+ this._lastResponseHeaders = resp.headers();
17
+ this._lastResponseStatus = resp.status();
18
+ }
19
+ } catch (e) { /* ignore */ }
20
+ });
21
+ });
22
+
23
+ async function getHeaders(world) {
24
+ if (world._lastResponseHeaders) return world._lastResponseHeaders;
25
+ // Fallback: fetch current URL via Playwright request context to get headers.
26
+ const url = world.page.url();
27
+ if (!url || url === 'about:blank') return {};
28
+ try {
29
+ const resp = await world.page.request.get(url);
30
+ return resp.headers();
31
+ } catch (e) {
32
+ return {};
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Assert the most recent navigation response carried a header (case-insensitive).
38
+ *
39
+ * Example #1: Then the response should contain the header "content-type"
40
+ * Example #2: Then the response should contain the header "cache-control"
41
+ * Example #3: And the response should contain the header "x-frame-options"
42
+ * Example #4: Then the response should contain the header "set-cookie"
43
+ * Example #5: Then the response should contain the header "etag"
44
+ *
45
+ */
46
+ Then('the response should contain the header {string}', async function (name) {
47
+ const h = await getHeaders(this);
48
+ assert.ok(Object.keys(h).map((k) => k.toLowerCase()).includes(name.toLowerCase()), `Header "${name}" not present.`);
49
+ });
50
+
51
+ /**
52
+ * Assert the most recent navigation response did NOT carry a header.
53
+ *
54
+ * Example #1: Then the response should not contain the header "x-fake-header"
55
+ * Example #2: Then the response should not contain the header "x-powered-by"
56
+ * Example #3: And the response should not contain the header "server"
57
+ * Example #4: Then the response should not contain the header "x-aspnet-version"
58
+ * Example #5: Then the response should not contain the header "x-debug-token"
59
+ *
60
+ */
61
+ Then('the response should not contain the header {string}', async function (name) {
62
+ const h = await getHeaders(this);
63
+ assert.ok(!Object.keys(h).map((k) => k.toLowerCase()).includes(name.toLowerCase()), `Header "${name}" should not be present.`);
64
+ });
65
+
66
+ /**
67
+ * Assert a header's value contains a substring.
68
+ *
69
+ * Example #1: Then the response header "content-type" should contain the value "html"
70
+ * Example #2: Then the response header "cache-control" should contain the value "no-cache"
71
+ * Example #3: And the response header "content-type" should contain the value "charset=utf-8"
72
+ * Example #4: Then the response header "set-cookie" should contain the value "session="
73
+ * Example #5: Then the response header "x-frame-options" should contain the value "DENY"
74
+ *
75
+ */
76
+ Then('the response header {string} should contain the value {string}', async function (name, value) {
77
+ const h = await getHeaders(this);
78
+ const key = Object.keys(h).find((k) => k.toLowerCase() === name.toLowerCase());
79
+ assert.ok(key, `Header "${name}" not present.`);
80
+ assert.ok(String(h[key]).indexOf(value) !== -1, `Header "${name}"="${h[key]}" does not contain "${value}".`);
81
+ });
82
+
83
+ /**
84
+ * Assert a header's value does NOT contain a substring (or the header is absent).
85
+ *
86
+ * Example #1: Then the response header "content-type" should not contain the value "application/json"
87
+ * Example #2: Then the response header "cache-control" should not contain the value "public"
88
+ * Example #3: And the response header "content-type" should not contain the value "xml"
89
+ * Example #4: Then the response header "set-cookie" should not contain the value "Domain=other"
90
+ * Example #5: Then the response header "x-frame-options" should not contain the value "ALLOW"
91
+ *
92
+ */
93
+ Then('the response header {string} should not contain the value {string}', async function (name, value) {
94
+ const h = await getHeaders(this);
95
+ const key = Object.keys(h).find((k) => k.toLowerCase() === name.toLowerCase());
96
+ if (!key) return;
97
+ assert.ok(String(h[key]).indexOf(value) === -1, `Header "${name}" should not contain "${value}".`);
98
+ });
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ const { friendly } = require('./webship');
4
+
5
+ // Set viewport dimensions and named breakpoints.
6
+
7
+ const { Given, When } = require('@cucumber/cucumber');
8
+
9
+ const DEFAULT_BREAKPOINTS = {
10
+ xs: { width: 375, height: 667 },
11
+ sm: { width: 576, height: 800 },
12
+ md: { width: 768, height: 1024 },
13
+ lg: { width: 992, height: 768 },
14
+ xl: { width: 1200, height: 900 },
15
+ xxl: { width: 1400, height: 900 },
16
+ xxxl: { width: 1920, height: 1080 },
17
+ mobile: { width: 375, height: 667 },
18
+ tablet: { width: 768, height: 1024 },
19
+ desktop: { width: 1200, height: 900 },
20
+ };
21
+
22
+ function getBreakpoints(world) {
23
+ if (!world._breakpoints) {
24
+ const cfg = (world.parameters && world.parameters.selectors && world.parameters.selectors.breakpoints) || {};
25
+ world._breakpoints = { ...DEFAULT_BREAKPOINTS, ...cfg };
26
+ }
27
+ return world._breakpoints;
28
+ }
29
+
30
+ /**
31
+ * Replace the breakpoint registry for the current scenario from a data table.
32
+ *
33
+ * Example #1: Given the following responsive breakpoints:
34
+ * | mobile | 375 | 667 |
35
+ * | tablet | 768 | 1024 |
36
+ * | desktop | 1200 | 900 |
37
+ * Example #2: Given the following responsive breakpoints:
38
+ * | watch | 280 | 280 |
39
+ * | phablet | 414 | 896 |
40
+ * Example #3: And the following responsive breakpoints:
41
+ * | xs | 320 | 480 |
42
+ * | sm | 480 | 800 |
43
+ * Example #4: Given the following responsive breakpoints:
44
+ * | hd | 1280 | 720 |
45
+ * | full-hd | 1920 | 1080 |
46
+ * Example #5: Given the following responsive breakpoints:
47
+ * | a11y | 320 | 480 |
48
+ * | print | 794 | 1123 |
49
+ *
50
+ */
51
+ Given('the following responsive breakpoints:', async function (table) {
52
+ const map = {};
53
+ for (const row of table.raw()) {
54
+ const [name, w, h] = row;
55
+ map[name] = { width: parseInt(w, 10), height: parseInt(h, 10) };
56
+ }
57
+ this._breakpoints = { ...DEFAULT_BREAKPOINTS, ...map };
58
+ });
59
+
60
+ /**
61
+ * Resize the viewport to a registered named breakpoint.
62
+ *
63
+ * Built-in names: `xs`, `sm`, `md`, `lg`, `xl`, `xxl`, `xxxl`, `mobile`,
64
+ * `tablet`, `desktop`. Project-defined names override built-ins.
65
+ *
66
+ * Example #1: When I set the viewport to the "mobile" breakpoint
67
+ * Example #2: When I set the viewport to the "tablet" breakpoint
68
+ * Example #3: And we set the viewport to the "desktop" breakpoint
69
+ * Example #4: When I set the viewport to the "xl" breakpoint
70
+ * Example #5: When I set the viewport to the "xxxl" breakpoint
71
+ *
72
+ */
73
+ When(/^(I |we )*set the viewport to the "([^"]*)" breakpoint$/, async function (pronoun, name) {
74
+ const bps = getBreakpoints(this);
75
+ const bp = bps[name];
76
+ if (!bp) throw friendly(`Unknown breakpoint "${name}".`);
77
+ await this.page.setViewportSize({ width: bp.width, height: bp.height });
78
+ });
79
+
80
+ /**
81
+ * Resize the viewport width while keeping the current height.
82
+ *
83
+ * Example #1: When I set the viewport width to 1200
84
+ * Example #2: When I set the viewport width to 375
85
+ * Example #3: And we set the viewport width to 1920
86
+ * Example #4: When I set the viewport width to 768
87
+ * Example #5: When I set the viewport width to 1024
88
+ *
89
+ */
90
+ When(/^(I |we )*set the viewport width to (\d+)$/, async function (pronoun, w) {
91
+ w = parseInt(w, 10);
92
+ const cur = this.page.viewportSize() || { height: 800 };
93
+ await this.page.setViewportSize({ width: w, height: cur.height });
94
+ });
95
+
96
+ /**
97
+ * Resize the viewport height while keeping the current width.
98
+ *
99
+ * Example #1: When I set the viewport height to 800
100
+ * Example #2: When I set the viewport height to 1024
101
+ * Example #3: And we set the viewport height to 1080
102
+ * Example #4: When I set the viewport height to 667
103
+ * Example #5: When I set the viewport height to 900
104
+ *
105
+ */
106
+ When(/^(I |we )*set the viewport height to (\d+)$/, async function (pronoun, h) {
107
+ h = parseInt(h, 10);
108
+ const cur = this.page.viewportSize() || { width: 1200 };
109
+ await this.page.setViewportSize({ width: cur.width, height: h });
110
+ });
111
+
112
+ /**
113
+ * Resize the viewport to an explicit width-by-height pair.
114
+ *
115
+ * Example #1: When I set the viewport to 1200 by 800
116
+ * Example #2: When I set the viewport to 375 by 667
117
+ * Example #3: And we set the viewport to 1920 by 1080
118
+ * Example #4: When I set the viewport to 768 by 1024
119
+ * Example #5: When I set the viewport to 1024 by 768
120
+ *
121
+ */
122
+ When(/^(I |we )*set the viewport to (\d+) by (\d+)$/, async function (pronoun, w, h) {
123
+ w = parseInt(w, 10); h = parseInt(h, 10);
124
+ await this.page.setViewportSize({ width: w, height: h });
125
+ });
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ // Lightweight REST testing — distinct from the existing api.steps.js steps
4
+ // Preserves exact step phrasing for compatibility.
5
+
6
+ const { Given, When, Then } = require('@cucumber/cucumber');
7
+ const assert = require('assert');
8
+ const axios = require('axios');
9
+
10
+ function ensureState(world) {
11
+ if (!world._rest) world._rest = { headers: {}, response: null };
12
+ return world._rest;
13
+ }
14
+
15
+ /**
16
+ * Add an HTTP header to subsequent REST requests.
17
+ *
18
+ * Example #1: Given a REST header "Authorization" with value "Bearer abc123"
19
+ * Example #2: Given a REST header "Accept" with value "application/json"
20
+ * Example #3: And a REST header "X-Request-ID" with value "req-001"
21
+ * Example #4: Given a REST header "Content-Type" with value "application/json"
22
+ * Example #5: Given a REST header "X-API-Key" with value "key-xyz"
23
+ *
24
+ */
25
+ Given('a REST header {string} with value {string}', async function (name, value) {
26
+ ensureState(this).headers[name] = value;
27
+ });
28
+
29
+ /**
30
+ * Send an HTTP request without a body.
31
+ *
32
+ * Example #1: When I send a REST "GET" request to "/api/users"
33
+ * Example #2: When I send a REST "DELETE" request to "/api/orders/1"
34
+ * Example #3: And we send a REST "GET" request to "https://example.com/api/health"
35
+ * Example #4: When I send a REST "GET" request to "/api/me"
36
+ * Example #5: When I send a REST "DELETE" request to "/api/cart/items/42"
37
+ *
38
+ */
39
+ When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)"$/, async function (pronoun, method, url) {
40
+ const s = ensureState(this);
41
+ const target = url.startsWith('http') ? url : (this.launchUrl || '') + url;
42
+ s.response = await axios.request({
43
+ method, url: target, headers: s.headers, validateStatus: () => true,
44
+ });
45
+ });
46
+
47
+ /**
48
+ * Send an HTTP request with a doc-string body (raw text, JSON, or form-encoded).
49
+ *
50
+ * Example #1: When I send a REST "POST" request to "/api/users" with body:
51
+ * """
52
+ * {"name": "Alice"}
53
+ * """
54
+ * Example #2: When I send a REST "PUT" request to "/api/users/1" with body:
55
+ * """
56
+ * {"role": "admin"}
57
+ * """
58
+ * Example #3: And we send a REST "PATCH" request to "/api/orders/1" with body:
59
+ * """
60
+ * {"status": "shipped"}
61
+ * """
62
+ * Example #4: When I send a REST "POST" request to "/api/login" with body:
63
+ * """
64
+ * username=alice&password=s3cret
65
+ * """
66
+ * Example #5: When I send a REST "POST" request to "/webhooks/event" with body:
67
+ * """
68
+ * {"event": "ping"}
69
+ * """
70
+ *
71
+ */
72
+ When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)" with body:$/, async function (pronoun, method, url, body) {
73
+ const s = ensureState(this);
74
+ const target = url.startsWith('http') ? url : (this.launchUrl || '') + url;
75
+ s.response = await axios.request({
76
+ method, url: target, headers: s.headers, data: body, validateStatus: () => true,
77
+ });
78
+ });
79
+
80
+ /**
81
+ * Assert the most recent REST response carried an expected status code.
82
+ *
83
+ * Example #1: Then the REST response status code should be 200
84
+ * Example #2: Then the REST response status code should be 201
85
+ * Example #3: And the REST response status code should be 401
86
+ * Example #4: Then the REST response status code should be 404
87
+ * Example #5: Then the REST response status code should be 500
88
+ *
89
+ */
90
+ Then('the REST response status code should be {int}', async function (code) {
91
+ const s = ensureState(this);
92
+ assert.ok(s.response, 'No REST response captured.');
93
+ assert.strictEqual(s.response.status, code);
94
+ });
95
+
96
+ /**
97
+ * Assert the most recent REST response body contains a substring.
98
+ *
99
+ * Example #1: Then the REST response should contain "Alice"
100
+ * Example #2: Then the REST response should contain "id"
101
+ * Example #3: And the REST response should contain "shipped"
102
+ * Example #4: Then the REST response should contain "ok"
103
+ * Example #5: Then the REST response should contain "Welcome"
104
+ *
105
+ */
106
+ Then('the REST response should contain {string}', async function (text) {
107
+ const s = ensureState(this);
108
+ assert.ok(s.response, 'No REST response captured.');
109
+ const body = typeof s.response.data === 'string' ? s.response.data : JSON.stringify(s.response.data);
110
+ assert.ok(body.indexOf(text) !== -1, `REST response does not contain "${text}".`);
111
+ });
@@ -27,6 +27,7 @@
27
27
  const { When, Then, Before, After, AfterStep, BeforeAll } = require('@cucumber/cucumber');
28
28
  const fs = require('fs');
29
29
  const path = require('path');
30
+ const { pad } = require('./webship');
30
31
 
31
32
  function pick(envVal, paramVal, fallback) {
32
33
  if (envVal !== undefined && envVal !== '') return envVal;
@@ -70,11 +71,6 @@ function resolveConfig(parameters) {
70
71
  // ---------------------------------------------------------------------------
71
72
  // Filename tokenizer
72
73
  // ---------------------------------------------------------------------------
73
- function pad(n, w) {
74
- const s = String(n);
75
- return s.length >= w ? s : '0'.repeat(w - s.length) + s;
76
- }
77
-
78
74
  function formatDate(d, format) {
79
75
  const yyyy = d.getFullYear();
80
76
  const MM = pad(d.getMonth() + 1, 2);
@@ -0,0 +1,189 @@
1
+ 'use strict';
2
+
3
+ // All scroll step definitions live in this file.
4
+ //
5
+ // Vertical: down / up / to top / to bottom (page or scoped element).
6
+ // Horizontal: right / left / to start / to end (page or scoped element).
7
+ //
8
+ // Default delta when no number is supplied is 350 px.
9
+
10
+ const { When } = require('@cucumber/cucumber');
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // Vertical scrolling — page
14
+ // ---------------------------------------------------------------------------
15
+
16
+ /**
17
+ * Scrolls the page down by a custom number of pixels (default 350).
18
+ *
19
+ * Example #1: And I scroll down
20
+ * Example #2: When I scroll down 800
21
+ * Example #3: And we scroll down 500
22
+ * Example #4: When scrolling down 1200
23
+ *
24
+ */
25
+ When(/^(I scroll|we scroll|scrolling)? down(?: (\d+))?$/, async function (pronounCase, numValue) {
26
+ await this.page.evaluate((v) => window.scrollBy(0, v), numValue ? parseInt(numValue, 10) : 350);
27
+ });
28
+
29
+ /**
30
+ * Scrolls the page up by a custom number of pixels (default 350).
31
+ *
32
+ * Example #1: And I scroll up
33
+ * Example #2: When I scroll up 1000
34
+ * Example #3: And we scroll up 300
35
+ * Example #4: When scrolling up 750
36
+ *
37
+ */
38
+ When(/^(I scroll|we scroll|scrolling)? up(?: (\d+))?$/, async function (pronounCase, numValue) {
39
+ await this.page.evaluate((v) => window.scrollBy(0, -v), numValue ? parseInt(numValue, 10) : 350);
40
+ });
41
+
42
+ /**
43
+ * Scrolls to the very top of the current page.
44
+ *
45
+ * Example #1: When I scroll to top
46
+ * Example #2: And we scroll to the top
47
+ * Example #3: When scrolling to the top of the page
48
+ *
49
+ */
50
+ When(/^(I scroll|we scroll|scrolling)? to( the)* top( of the page)*$/, async function (pronounCase, theCase, pageCase) {
51
+ await this.page.evaluate(() => window.scrollTo(0, 0));
52
+ });
53
+
54
+ /**
55
+ * Scrolls to the bottom of the current page.
56
+ *
57
+ * Example #1: When I scroll to the bottom
58
+ * Example #2: And we scroll to bottom
59
+ * Example #3: When scrolling to the bottom of the page
60
+ *
61
+ */
62
+ When(/^(I scroll|we scroll|scrolling)? to( the)* bottom( of the page)*$/, async function (pronounCase, theCase, pageCase) {
63
+ await this.page.evaluate(() => {
64
+ window.scrollTo(0, document.body.scrollHeight);
65
+ document.querySelectorAll('*').forEach(el => {
66
+ const s = window.getComputedStyle(el);
67
+ if ((s.overflowY === 'scroll' || s.overflowY === 'auto') && el.scrollHeight > el.clientHeight) {
68
+ el.scrollTop = el.scrollHeight;
69
+ el.dispatchEvent(new Event('scroll', { bubbles: true }));
70
+ }
71
+ });
72
+ });
73
+ });
74
+
75
+ // ---------------------------------------------------------------------------
76
+ // Vertical scrolling — scoped to a CSS selector
77
+ // ---------------------------------------------------------------------------
78
+
79
+ /**
80
+ * Scrolls to the top of a specific element identified by a CSS selector.
81
+ *
82
+ * Example #1: When I scroll to top of "#off-canvas"
83
+ * Example #2: And we scroll to top of "#sidebar"
84
+ * Example #3: When scrolling to top of "#main-container"
85
+ *
86
+ */
87
+ When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, async function (pronounCase, selector) {
88
+ await this.page.locator(selector).evaluate(el => {
89
+ el.scrollTop = 0;
90
+ el.dispatchEvent(new Event('scroll', { bubbles: true }));
91
+ });
92
+ });
93
+
94
+ /**
95
+ * Scrolls to the bottom of a specific element identified by a CSS selector.
96
+ *
97
+ * Example #1: When I scroll to bottom of "#off-canvas"
98
+ * Example #2: And we scroll to bottom of "#sidebar"
99
+ * Example #3: When scrolling to bottom of "#main-container"
100
+ *
101
+ */
102
+ When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, async function (pronounCase, selector) {
103
+ await this.page.locator(selector).evaluate(el => {
104
+ el.scrollTop = el.scrollHeight;
105
+ el.dispatchEvent(new Event('scroll', { bubbles: true }));
106
+ });
107
+ });
108
+
109
+ // ---------------------------------------------------------------------------
110
+ // Horizontal scrolling — page
111
+ // ---------------------------------------------------------------------------
112
+
113
+ /**
114
+ * Scrolls the page right by a custom number of pixels (default 350).
115
+ *
116
+ * Example #1: And I scroll right
117
+ * Example #2: When I scroll right 1000
118
+ * Example #3: And we scroll right 300
119
+ * Example #4: When scrolling right 750
120
+ *
121
+ */
122
+ When(/^(I scroll|we scroll|scrolling)? right(?: (\d+))?$/, async function (pronounCase, numValue) {
123
+ await this.page.evaluate((v) => window.scrollBy(v, 0), numValue ? parseInt(numValue, 10) : 350);
124
+ });
125
+
126
+ /**
127
+ * Scrolls the page left by a custom number of pixels (default 350).
128
+ *
129
+ * Example #1: And I scroll left
130
+ * Example #2: When I scroll left 800
131
+ * Example #3: And we scroll left 500
132
+ * Example #4: When scrolling left 1200
133
+ *
134
+ */
135
+ When(/^(I scroll|we scroll|scrolling)? left(?: (\d+))?$/, async function (pronounCase, numValue) {
136
+ await this.page.evaluate((v) => window.scrollBy(-v, 0), numValue ? parseInt(numValue, 10) : 350);
137
+ });
138
+
139
+ /**
140
+ * Scrolls to the start (horizontal origin) of the page.
141
+ *
142
+ * Example #1: When I scroll to start
143
+ * Example #2: And we scroll to the start
144
+ * Example #3: When scrolling to the start of the page
145
+ *
146
+ */
147
+ When(/^(I scroll|we scroll|scrolling)? to( the)* start( of the page)*$/, async function (pronounCase, theCase, pageCase) {
148
+ await this.page.evaluate(() => window.scrollTo(0, window.scrollY));
149
+ });
150
+
151
+ /**
152
+ * Scrolls to the end (horizontal maximum) of the page.
153
+ *
154
+ * Example #1: When I scroll to the end
155
+ * Example #2: And we scroll to end
156
+ * Example #3: When scrolling to the end of the page
157
+ *
158
+ */
159
+ When(/^(I scroll|we scroll|scrolling)? to( the)* end( of the page)*$/, async function (pronounCase, theCase, pageCase) {
160
+ await this.page.evaluate(() => window.scrollTo(document.body.scrollWidth, window.scrollY));
161
+ });
162
+
163
+ // ---------------------------------------------------------------------------
164
+ // Horizontal scrolling — scoped to a CSS selector
165
+ // ---------------------------------------------------------------------------
166
+
167
+ /**
168
+ * Scrolls to the start of a specific element identified by a CSS selector.
169
+ *
170
+ * Example #1: When I scroll to start of "#off-canvas"
171
+ * Example #2: And we scroll to start of "#sidebar"
172
+ * Example #3: When scrolling to start of "#main-container"
173
+ *
174
+ */
175
+ When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, async function (pronounCase, selector) {
176
+ await this.page.locator(selector).evaluate(el => { el.scrollLeft = 0; });
177
+ });
178
+
179
+ /**
180
+ * Scrolls to the end of a specific element identified by a CSS selector.
181
+ *
182
+ * Example #1: When I scroll to end of "#off-canvas"
183
+ * Example #2: And we scroll to end of "#sidebar"
184
+ * Example #3: When scrolling to end of "#main-container"
185
+ *
186
+ */
187
+ When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, async function (pronounCase, selector) {
188
+ await this.page.locator(selector).evaluate(el => { el.scrollLeft = el.scrollWidth; });
189
+ });